react 搜集复选框组的状态

react 搜集复选框组的状态

 

<div className="m-plugin-control-filter-item">
	<CheckBox defaultChecked={true} checked={ rank.indexOf(0) >= 0 ? true : false } onClick={this.handleRank.bind(this, 0)} >高危</CheckBox>
</div>
<div className="m-plugin-control-filter-item">
	<CheckBox defaultChecked={true} checked={ rank.indexOf(1) >= 0 ? true : false } onClick={this.handleRank.bind(this, 1)} >中危</CheckBox>
</div>	
<div className="m-plugin-control-filter-item">
	<CheckBox defaultChecked={true} checked={ rank.indexOf(2) >= 0 ? true : false } onClick={this.handleRank.bind(this, 2)} >低危</CheckBox>
</div>
  handleRank(rank) {
    let index = this.state.rank.indexOf(rank)
    if (index >= 0) {
      this.state.rank.splice(index, 1)
    } else {
      this.state.rank.push(rank)
    }
    this.setState({
      rank: this.state.rank
    })
  }

 

相关文章:

  • 2022-01-08
  • 2022-12-23
  • 2022-01-22
  • 2022-12-23
  • 2022-12-23
  • 2021-08-18
  • 2022-12-23
  • 2021-10-11
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-30
相关资源
相似解决方案