react 搜集复选框组的状态

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

})

}

以上是 react 搜集复选框组的状态 的全部内容, 来源链接: utcz.com/z/383730.html

回到顶部