首页 > 解决方案 > 如何在reactjs中选择多个复选框?

问题描述

问题是我需要传递对象数组,我无法获得我接受的数据。我接受的数据将是这种格式。但是,用户可以使用 unchecked 来删除。

 {

    notification : {group:["can_view","can_create", "can_delete","can_update","can_upload","can_download"],
    topGroup:["can_view","can_create", "can_delete","can_update","can_upload","can_download"}
    }

  handleAllChecked = (id, role, data) => event => {
    let fruites = this.state.fruites;
    fruites
      .filter(f => f.groupId === id)
      .forEach(fruite => {
        if (event.target.checked === true) {
          fruite.isChecked = event.target.checked;

          console.log(data);
        } else {
          fruite.isChecked = false;
        }
      });

    this.setState({ fruites: fruites });
  };

这是我的codesanbox,你可以很容易理解 https://codesandbox.io/s/fragrant-http-v35lf

标签: arraysreactjsobjectcheckbox

解决方案


推荐阅读