【问题标题】:How to access fetched data from ReferenceInput to fill ReferenceArrayInput choices in react admin?如何访问从 ReferenceInput 获取的数据以填充 React admin 中的 ReferenceArrayInput 选择?
【发布时间】:2018-09-04 10:38:29
【问题描述】:

当我获取数据时

<ReferenceInput
source="estateId"
reference="estates"
>
<SelectInput optionText="name" />
</ReferenceInput>

我得到了这样的每个庄园的答案:

{
"id": 5,
"name": "test",
"livingUnits": [
{
"id": 1,
"name": "all"
},
{
"id": 2,
"name": "1."
}
]
}

如何访问 livingunits 信息以填写 ReferenceArrayInput 选项?

<ReferenceArrayInput
source="livingUnitIds"            
>
<SelectArrayInput>
<ChipField source="name" />
</SelectArrayInput>              
</ReferenceArrayInput>

【问题讨论】:

    标签: react-admin


    【解决方案1】:

    我不认为你可以,我在源代码上搜索了很多,但没有找到一个干净的解决方案。 &lt;ReferenceArrayInput&gt; 需要一个包含相关资源 id 的数组,然后它会在 dataProvider 中查询资源和数组上的 id。我应用的一个解决方案是更改请求的答案以提供一个属性,该属性是一个具有相关资源 id 的数组,在您的示例中,房地产的答案应该是这样的:

    { "id": 5, "name": "test", "livingUnitsIds": [1, 2] }

    我这样做是因为我可以控制后端,如果这不是你的情况,可能你需要实现一个自定义 &lt;ReferenceInput&gt; 或一个在组件 onComponentDidMount 生命周期方法上获取所需数据的组件。

    【讨论】:

      猜你喜欢
      • 2014-06-04
      • 2021-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-24
      • 2018-09-12
      相关资源
      最近更新 更多