【发布时间】:2019-03-11 15:54:08
【问题描述】:
下面是我的页面截图:
我使用 reactstrap 下拉菜单将按钮与菜单绑定。每当我单击一个按钮时,所有下拉菜单都会打开。下面的快照是下拉问题:
这是我使用的代码:
import React, { Component } from 'react';
import './Home.css';
import { Dropdown, DropdownToggle, DropdownMenu, DropdownItem } from 'reactstrap';
export class Home extends Component {
constructor(props) {
super(props);
let $this = this;
$this.toggle = $this.toggle.bind($this);
$this.state =
{
dropdownOpen: false
};
}
toggle() {
this.setState(prevState => ({
dropdownOpen: !prevState.dropdownOpen
}));
}
render() {
return (
<div className="table-div table-responsive-xl">
<table className="table table-hover">
<thead>
<tr>
<th scope="col" />
<th scope="col">Authentication</th>
</tr>
</thead>
<tbody>
{this.state.slackmembers.map((item, key) => {
return (
<tr key={key}>
<td scope="row" />
<td>{item.Authentication}</td>
<td>
<Dropdown isOpen={this.state.dropdownOpen} toggle={this.toggle}>
<DropdownToggle className="menu-button">
<i className="fa fa-ellipsis-h" aria-hidden="true" type="ellipsis" />
</DropdownToggle>
<DropdownMenu>
<DropdownItem style={{ fontWeight: 500, color: 'black' }}>First</DropdownItem>
<DropdownItem style={{ fontWeight: 500, color: 'black' }}>Second</DropdownItem>
<DropdownItem divider />
<DropdownItem style={{ fontWeight: 500, color: 'red' }}>Last </DropdownItem>
</DropdownMenu>
</Dropdown>
</td>
</tr>
);
})}
</tbody>
</table>
</div>
);
}
我不知道我的方法有什么问题。有人可以帮忙解决这个问题吗?
【问题讨论】:
标签: reactjs drop-down-menu reactstrap