Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k 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 Answer

0 votes
by (71.8m points)

把 checklist 作为 state 来管理


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...