大前端

前端学习之家-大前端

React开发(227):根据数组判断是否显示

    const { selectedList } = this.state;

    const check = e.target.checked;
    let arr = selectedList;
    if (check && selectedList.indexOf(row.code) === -1) {
      arr.push(row.code);
      console.log(arr, 'arr1');
    } else {
      let index = arr.find((item) => item === row.code);
      arr = arr.splice(1, index);
      console.log(arr, 'arr2');
    }
    console.log(arr, 'arr3');
    console.log(arr.length > 0 ? true : false, 'isAfter');
    this.setState({ selectedList: arr, isAfter: arr.length >
 0 ? true : false });

发表评论:

Copyright Your WebSite.Some Rights Reserved.