【发布时间】:2019-06-27 03:42:45
【问题描述】:
我有两个 Typeahead (react-bootstrap-typeahead) 组件,我想在按下按钮时反转选定的值。以状态存储的数据正确变化。但我无法将更改的选择设置为 Typeahead 的值。
使用selected prop 设置选定对象但出现一些错误:
Warning: [react-bootstrap-typeahead] `defaultInputValue` will be overridden by the value from `selected`.
Warning: Failed prop type: Invalid prop `selected` supplied to `TypeaheadContainer(WrappedTypeahead)`.
我的 HOC
<TypeaheadComponent
onSearch={value => getOriginPlaces(value, index)}
data={route.originResults}
onInputChange={value => originPlaceInputOnChange(value, index)}
onSelect={item => originPlaceOnSelect(item, index)}
selected={route.originPlace} // object
inputValue={route.originPlaceInputValue} // string from originPlaceInputOnChange()
/>
和 AsyncTypeahead (react-bootstrap-typeahead)
<AsyncTypeahead
promptText={<PromptText />}
searchText={<Loading />}
emptyLabel={<NotFound />}
inputProps={{...}}
options={props.data}
maxResults={10}
paginationText={...}
labelKey="name"
filterBy={[...]}
onSearch={props.onSearch}
minLength={2}
selectHintOnEnter={true}
onInputChange={props.onInputChange}
onChange={selected => props.onSelect(selected[0])} // set first object of array
defaultInputValue={props.inputValue || ''}
selected={props.selected} // object
renderMenu={...}
/>
我该怎么做?或者我哪里错了
【问题讨论】:
标签: reactjs typeahead react-bootstrap-typeahead