问题描述
我有React组件:
<Dropdown
placeholder={field[propName].label}
id={propName}
fluid
multiple
selection
search
defaultValue={defaultOptions}
options={options}
/>
所以期权
和 defaultOptions
是相同的结构数组 {text:'string,value:'string'}
。
So options
and defaultOptions
is the same structure arrays {text: 'string, value: 'string'}
.
在语义UI源代码中,我发现:
In semantic UI source code I found this:
/** Initial value or value array if multiple. */
defaultValue: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
PropTypes.arrayOf(PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
])),
])
上面我的代码给出错误的原因是:
That the reason why my code above gives me error:
`Warning: Failed propType: Invalid prop `defaultValue` supplied to `Dropdown`. Check the render method of `View`.`
所以问题是我应该如何设置defaultValue for multi选择类型的Dropdown?
So question is how then I should set defaultValue for multi selection type of Dropdown?
推荐答案
defaultValue不能是语义UI反应的对象。它只能是一个价值。 。如果你看一下defaultValue的道具,文档会说它可以是字符串,数字或arrayOf。
defaultValue cannot be an object for semantic-UI-react. It can only be a value. http://react.semantic-ui.com/modules/dropdown. If you look at the props of defaultValue, the docs say that it can be a string, number, or arrayOf.
我通常将我的设置值设为下拉 - 使用immutabilityJS - 当它被切换时更改。
I usually set mine to value of the dropdown - using immutabilityJS - when it is switched onChange.
<Dropdown
placeholder={field[propName].label}
id={propName}
fluid
multiple
selection
search
defaultValue={dropdownList.get('forWhat')}
options={options}
onChange={(e, {value}) => this.updateDropdownList('forWhat',[value:value, text:"works"])}
/>
这篇关于Semantic-UI-React,selection,multi,不能设置defaultValue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!