简体   繁体   English

Ant Design/React - 如何在列表中使用复选框?

[英]Ant Design/React - How to use checkboxes in a list?

I'm new to React and Ant Design.我是 React 和 Ant Design 的新手。

I want to use a List that has a Checkbox for each item.我想使用每个项目都有一个复选框的列表。 As in the attached example:如附件示例所示:

  <Checkbox indeterminate={indeterminate} onChange={onCheckAllChange} checked={checkAll}>
    Check all
  </Checkbox>
  <Divider />
  <List
    dataSource={plainOptions}
    renderItem={value => (
      <CheckboxGroup options={plainOptions} value={checkedList} onChange={onChange} />
    )}
  />

https://codepen.io/antoinemy/pen/dymvwJG https://codepen.io/antoinemy/pen/dymvwJG

However I would simply like to replace the CheckboxGroup with a Checkbox but I can't do it through the List.但是,我只想用 Checkbox 替换 CheckboxGroup,但我无法通过 List 来完成。

Can someone show me a solution and explain to me?有人可以告诉我一个解决方案并向我解释吗?

I would like to eventually produce other things through this list.我想最终通过这个列表产生其他东西。 I'm not interested in the CheckboxGroup, I really want the List to deploy my items.我对 CheckboxGroup 不感兴趣,我真的希望 List 来部署我的项目。

Thank you, Antoine (FR)谢谢你,安托万(法国)

I think you can include the Checkbox components inside the List.Item and wrap the Checkbox.Group outside我认为您可以在 List.Item 中包含 Checkbox 组件并将 Checkbox.Group 包装在外面

Here is my example code https://codesandbox.io/s/basic-list-antd-4-21-7-forked-h6fejs?file=/demo.js这是我的示例代码https://codesandbox.io/s/basic-list-antd-4-21-7-forked-h6fejs?file=/demo.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM