我使用 React 检索带有复选框的数组数据。但是,如果我选中一个复选框,它会选中所有复选框。如果我选中一个复选框,我想显示一个文本框。我该如何解决?
class ColumnName extends Component {
constructor(props) {
super(props);
this.state = { checked: false };
}
render() {
if (!this.props.posts) {
return <div />;
}
const content = this.state.checked ? <div> Content </div> : null;
return (
<ul>
{this.props.posts.map(post => (
<div>
<Checkbox
checked={this.state.checked}
onChange={() => {
this.setState({
checked: !this.state.checked
});
}}
>
{post.title}
</Checkbox>
{content}
</div>
))}
</ul>
);
}
}
export default Search;