我有:
showDropdown(e) {
e.preventDefault();
document.addEventListener('click', this.closeDropdown);
this.setState({activeDropdown: "Only_show"})
}
closeDropdown() {
document.removeEventListener('click', this.closeDropdown);
}
...
<DropdownMenu text="New" count={127}/>
<DropdownMenu text="Only show"
isOpen={this.state.activeDropdown === "Only_show"}
onClick={this.showDropdown.bind(this)}>
<li>New</li>
<li>Old</li>
</DropdownMenu>
...
Dropdown.js
import React, {Component} from 'react';
export default class DropdownMenu extends Component {
constructor(props) {
super(props);
this.state = {
highlight: false,
count: this.props.count || 0,
selection: null
}
this.showDropdown = this.showDropdown.bind(this);
this.selectItem = this.selectItem.bind(this);
}
componentDidMount() {
}
selectItem(e) {
}
render() {
return <div className="dropdown__menu" onClick={this.props.onClick}>
{this.props.text} {this.state.count > 0 ? <b>{this.state.count}</b> : ''}
<div className="dropdown__content"
style={this.props.isOpen ? {'display': 'block'} : {'display': 'none'}}>
{this.props.children}
</div>
</div>
}
}
我在做什么错了?