首页 > 解决方案 > React-admin SelectInput 与选择一起使用时不显示编辑中的值

问题描述

我有一个状态字段,来自我的 API。它的值介于 0-3 之间。

我的回复是这样的:

{ status: 0 }

我可以在 Edit with TextInput 中显示值,它显示了值(在本例中为 0)。

但是我希望它使用 SelectInput 显示它,因为在编辑模式下我想更改状态的值。

我的 SelectInput 看起来像这样:

          <SelectInput label="Status" source="status" choices={[
                       { id: '0', name: 'elfogadásra vár' },
                       { id: '1', name: 'aktív' },
                       { id: '2', name: 'inaktív' },
                       { id: '3', name: 'archív' },
                       ]} 
                       optionText="name" 
                       optionValue="id" 
          />

不幸的是,当我保存它并刷新我的页面时,我的状态没有显示当前值(在这种情况下为 0,它应该显示我'elfogadasra var',但它是空的)

我做错了什么?

标签: reactjsreact-nativereact-admin

解决方案


我实现这一目标的方式如下

<ReferenceInput label="Country" source='country.id' reference="Country"  sort={{ field: 'name', order: 'ASC' }} alwaysOn>
   <SelectInput optionText="name" optionValue="id" allowEmpty />
</ReferenceInput>

我需要从该数据库加载我的选择,但概念是相同的......我怀疑你使用的源代码是错误的..查看redux开发工具..在状态->表单->记录下-form --> values 你应该看到类似 status.id 的东西,你应该使用它来代替 source .. 我的表单 country {id: 2} 有相同类型的对象......但这不是你的用于获取输入以显示您现有的值...

您的解决方案可能就像在源代码中调用 diff 值一样简单,但您会通过查看状态 {status: 0} 必须在其前面有类似状态的东西 --> {status: 0}


推荐阅读