Javascript REST上的管理员:onNewRequest无法自动完成输入?
我想要一个自定义的输入组件 1) 具有允许选择“字段”资源的自动完成组件 2) 选择“字段”后,根据所选“字段”类型填充另一个SelectInput 我目前拥有的是:Javascript REST上的管理员:onNewRequest无法自动完成输入?,javascript,reactjs,redux,admin-on-rest,Javascript,Reactjs,Redux,Admin On Rest,我想要一个自定义的输入组件 1) 具有允许选择“字段”资源的自动完成组件 2) 选择“字段”后,根据所选“字段”类型填充另一个SelectInput 我目前拥有的是: const renderAutoComplete = ({ input, meta, ...rest }) => { return ( <AutoComplete {...rest} /> ) } render () {
const renderAutoComplete = ({ input, meta, ...rest }) => {
return (
<AutoComplete {...rest} />
)
}
render () {
return (
<div>
<div>
<Field
component={renderAutoComplete}
name={this.props.fieldSource}
hintText="Field"
dataSource={this.state.fields}
dataSourceConfig={{ text: 'title', value: 'id' }}
openOnFocus={true}
filter={AutoComplete.caseInsensitiveFilter}
onNewRequest={(chosen) => this.handleNewRequest(chosen)}
/>
</div>
<div>
<Field
component={SelectInput}
label="Type-dependent"
name={this.props.typeSource}
choices={this.state.availableChoices}
/>
</div>
</div>
)
}
…此日志记录到控制台,但请求中未设置我的值。您可以给我指出文档或源代码中正确的部分,以澄清我在这里必须做的事情吗?您确定onNewRequest返回函数参数中的值吗?物料UI组件返回eventsHi@kunalpareek,您指的是什么值?当前,
handleNewRequest
-函数仅设置此.state.availableechoices
,以便第二个字段接收正确的选择。当您将自动完成输入
用作字段组件时,你应该把onnerRequest
道具放在options
prop中。因为AutocompleteInput
不直接接受onnerRequest
,但是你可以使用options
来覆盖内置的onnerRequest
道具。你是对的。在选项中包含onnerRequest
并不能解决所有问题。无法更新Redux表单状态,因为在替换onnerRequest
:input.onChange(选项[index][optionValue])时丢失了这部分代码
您确定onnerRequest返回函数参数中的值吗?物料UI组件返回eventsHi@kunalpareek,您指的是什么值?当前,handleNewRequest
-函数仅设置此.state.availableechoices
,以便第二个字段接收正确的选择。当您将自动完成输入
用作字段组件时,你应该把onnerRequest
道具放在options
prop中。因为AutocompleteInput
不直接接受onnerRequest
,但是你可以使用options
来覆盖内置的onnerRequest
道具。你是对的。在选项中包含onnerRequest
并不能解决所有问题。无法更新Redux表单状态,因为在替换onnerRequest
:input.onChange(选项[index][optionValue])时丢失了这部分代码代码>
<Field
component={AutocompleteInput}
name={this.props.fieldSource}
hintText="Feld"
choices={this.state.fields}
dataSourceConfig={{ text: 'title', value: 'id' }}
optionText="title"
optionValue="id"
filter={AutoComplete.caseInsensitiveFilter}
onNewRequest={(chosen) => this.handleNewRequest(chosen)}
/>
<Field
name="field"
component={AutocompleteInput}
choices={choices}
optionText="title"
optionValue="id"
filter={AutoComplete.caseInsensitiveFilter}
options={{
onNewRequest: (chosen, index) => console.log(chosen)
}}
/>