[英]How to get selected items on Fluent UI DetailsList component
I want to use DetailsList component https://developer.microsoft.com/en-us/fluentui#/controls/web/detailslist and select items.我想使用 DetailsList 组件https://developer.microsoft.com/en-us/fluentui#/controls/web/detailslist和 select 项目。 As I understand, the component doesn't provide us a prop to get selected items.据我了解,该组件没有为我们提供获取所选项目的道具。 I only see onActiveItemChanged
prop which is only giving me single item but not all selected items.我只看到onActiveItemChanged
道具,它只给我一个项目,而不是所有选定的项目。
Getting selected items in Fluent UI DetailsList 在 Fluent UI DetailsList 中获取选定的项目
Because of this reason -maybe I can also have other problem in the future-, I couldn't use state, as well.由于这个原因——也许我以后还会有其他问题——我也不能使用 state。
I will be very glad if I can get current selected checkboxes on DetailsList component.如果我能在 DetailsList 组件上获得当前选中的复选框,我将非常高兴。
I found the answer.我找到了答案。
import Selection
from @fluentui/react
从@fluentui/react
导入Selection
Add selection={selection}
to DetailsList props将selection={selection}
添加到 DetailsList 道具
and then do this before returning the component:然后在返回组件之前执行此操作:
const selection = new Selection({ onSelectionChanged: () => { const selectedItems = selection.getSelection(); // Do something with the selected items' console.log(selectedItems, 'ewgergre'); }, }); const selection = new Selection({ onSelectionChanged: () => { const selectedItems = selection.getSelection(); // 对选中的项目做一些事情 console.log(selectedItems, 'ewgergre'); }, });
I didn't understand why it doesn't format my code.我不明白为什么它不格式化我的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.