Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

ant design ,CheckboxGroup 全选问题

如何实现全选?控件是通过数据循环出来的。

在线demo:http://codepen.io/nbka/pen/LW...

代码:

const { Checkbox } = antd;

var testList = {
  'data': [
    {
      'lable': '组一',
      'value': 1,
      'action': [
        {
          'label': '组一1',
          'value': 11
        }, {
          'label': '组一2',
          'value': 12
        }
      ]
    }, {
      'lable': '组二',
      'value': 2,
      'action': [
        {
          'label': '组二1',
          'value': 21
        }, {
          'label': '组二2',
          'value': 22
        }
      ]
    }
  ],
  'code': 1,
  'message': '获取成功!'
};

const CheckboxGroup = Checkbox.Group;

const handleGroupChange = (checklist) => {
    console.clear();
    console.log(checklist);
  }

ReactDOM.render(
  <div>
    {testList.data.map((item,key) => {
      return(
        <div key={key} style={{marginBottom:'1em'}}>
            <Checkbox>{item.lable}</Checkbox>
            <CheckboxGroup onChange={handleGroupChange} options={item.action}/>
        </div>
      );
   })}
  </div>
, mountNode); 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

把 checklist 作为 state 来管理


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...