react快速实现多选框逻辑

 
 changeTagIndex = (num) => () => {
    this.setState(({ tagIndexList }) => ({
      tagIndexList: tagIndexList.includes(num)
        ? tagIndexList.filter(item => item !== num)
        : [...tagIndexList, num],
    }));
  }
 
  renderTagsItem = () => {
    let { tagIndexList } = this.state;//选择中的索引数组
    let self = this;
    let tagsArr = ["声音动听", "态度端正", "非常专业", "很耐心", "感觉效果很好"];
    return tagsArr.map(function (item, index) {
      return 
  • {item}
  • }) }

     

    你可能感兴趣的:(前端,reactjs)