我对 React
和 Semantic UI
也比较陌生。
有一个名为 Dropdown
的组件,带有属性 multiple
和 selection
,它允许选择多个项目。
在输出中我的状态如下所示:
const selectedItems = [
{key: 1, value: 1, text: 'Item 1'},
{key: 2, value: 2, text: 'Item 2'},
{key: 3, value: 3, text: 'Item 3'},
];
如何设置N个元素的数量限制?
非常感谢
最佳答案
Semantic UI React
下拉选项提供了一个名为 onAddItem
的函数。您必须使用value
数据 key 并执行如下操作:
const onAddItem = (event, data) => {
1.Fetch the state of the selected values, stored in the value key
2. Check if the limit is greater than 2
3. If the condition is met, then add
4. Else, show an error
}
关于javascript - 具有多项选择限制的下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49690980/