React 之antd Checkbox.Group 组,onchange事件及赋值

每个人的需求不一样,因此功能也会不一样,在此记录了项目中的Checkbox.Group组,新增了清空所有组的复选框,通过阅读文档,可以修改对应的value值达到清空的效果

onChange变化时需要把更新value的值,来对应匹配勾选中的复选框;

清空时也需要将value值置空,空数组及可

{Object.keys(filterConfig).map((key) => {
          return (
            
{filterConfig[key].title}
{ this.onChange(checkedValues, key); }} > {filterConfig[key].list.map((item, index) => { return ( {item.section}
{FilterResult[key][index]}
); })}
); })}
 onChange = (checkedValues, key) => {
    const filters = {};
    const filterValues = {};
    console.log(111, checkedValues, key);
    // eslint-disable-next-line array-callback-return
    Object.keys(filterConfig).map((keys) => {
      if (keys === key) {
        const filterLength = filterConfig[key].list.length;
        const arr2 = new Array(filterLength).fill(0);
        checkedValues.forEach((element) => {
          arr2[element] = 1;
        });
        filters[keys] = arr2;
        filterValues[keys] = checkedValues;
        this.props.onFilterCard(filters, filterValues);
      }
    });
  };
onFilterCard = (filters, filterValues) => {
    this.props.updateInfo({
      loading: true,
      filters: {
        ...this.props.TaskDetail.filters,
        ...filterValues,
      },
    });
    this.props.GetMoleculeDetail({
      ...this.props.TaskDetail.query,
      filters: {
        ...this.props.TaskDetail.query.filters,
        ...filters,
      },
    });
  };

 

你可能感兴趣的:(React基础,Ant,design实战)