如何从ReferenceInput访问提取的数据以填充react admin中的ReferenceArrayInput选项?

问题描述 投票:1回答:1

当我获取数据

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

我得到了这样的每个地产的答案:

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

如何访问livingunits信息以填充R​​eferenceArrayInput选项?

<ReferenceArrayInput
source="livingUnitIds"            
>
<SelectArrayInput>
<ChipField source="name" />
</SelectArrayInput>              
</ReferenceArrayInput>
react-admin
1个回答
0
投票

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

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

我这样做是因为我控制了后端,如果不是你的情况,可能你需要实现一个自定义的<ReferenceInput>或一个在组件onComponentDidMount生命周期方法中获取你想要的数据的组件。

© www.soinside.com 2019 - 2024. All rights reserved.