【发布时间】:2017-11-10 23:13:31
【问题描述】:
我确信这很简单,但我已经做了好几个小时了...... 我有一个 react-select 元素,我可以添加或编辑和更新,但无法弄清楚如何清除选择并将 DB 字段设置为 null。
组件
selectPriority(priority) {
this.updateAttribute("priorityId", priority.value)
this.updateAttribute("priority", priority.label)
}
选择元素
<Select
name="select_priority"
value={proposalService.priorityId ? proposalService.priorityId
: null}
options={priorities.map(p => ({
value: p.id,
label: p.name,
}))
.sort((a, b) => a.label < b.label)}
onChange={p => this.selectPriority(p) || null}
placeholder="Select Priority"
/>
在 React-Select 元素中单击“X”时出现控制台错误
ProposalServiceForm.js:86 Uncaught TypeError: Cannot read property 'value' of null
at ProposalServiceForm.selectPriority (ProposalServiceForm.js:86)
at Object.onChange (ProposalServiceForm.js:342)
at Object.setValue (Select.js:683)
at Object.clearValue (Select.js:748)
at Object.ReactErrorUtils.invokeGuardedCallback (ReactErrorUtils.js:69)
at executeDispatch (EventPluginUtils.js:85)
at Object.executeDispatchesInOrder (EventPluginUtils.js:105)
at executeDispatchesAndRelease (EventPluginHub.js:43)
at executeDispatchesAndReleaseTopLevel (EventPluginHub.js:54)
at Array.forEach (<anonymous>)
【问题讨论】:
标签: ruby-on-rails reactjs api react-select