如何使用 ReferenceManyField?
how to use ReferenceManyField?
目标 属性 of ReferenceManyField 不 运行 使用 react-admin.
我尊重文档中给出的逻辑。我什至确保我提供的数据具有不带子轨道的 id,因为我使用数据库 mongo db(其中标识符具有这种形式的 _id)。简而言之 ReferenceManyField returns 所有数据都给我,而不考虑目标 属性
export const HistoryHospitalListTest = props => (
<List title="Liste des Hôpitaux" {...props}>
<Datagrid>
<TextField source="id" />
<TextField source="slug" label="Years" />
<ReferenceManyField
reference="historyHospitals"
source="projectKey"
label="2019"
perPage={7}
allowEmpty={true}
>
<SingleFieldList>
<ChipField source="slug" />
</SingleFieldList>
</ReferenceManyField>
<EditButton />
</Datagrid>
</List>
);
抱歉,我已经找到解决方案好几次了
首先使用目标而不是源。
其次,将资源指向适当的路线(这里链接到主要路线的是医院)。
请注意,ReferenceManyField 基本上用于通过公共 属性 将主干道与其他道路连接起来(对于我来说,它是 projectKey,这是医院出现的主键)
确保 API returns id 像这个 id 而不是 _id
检查完以上所有内容后,我们的最终代码将如下所示:
export const HistoryHospitalListTest = props => (
<List title="Liste des Hôpitaux" {...props}>
<Datagrid>
<TextField source="id" />
<TextField source="slug" label="Years" />
<ReferenceManyField
reference="historyHospitals"
target="projectKey"
label="2019"
perPage={7}
allowEmpty={true}
>
<SingleFieldList>
<ChipField source="slug" />
</SingleFieldList>
</ReferenceManyField>
<EditButton />
</Datagrid>
</List>
);
目标 属性 of ReferenceManyField 不 运行 使用 react-admin.
我尊重文档中给出的逻辑。我什至确保我提供的数据具有不带子轨道的 id,因为我使用数据库 mongo db(其中标识符具有这种形式的 _id)。简而言之 ReferenceManyField returns 所有数据都给我,而不考虑目标 属性
export const HistoryHospitalListTest = props => (
<List title="Liste des Hôpitaux" {...props}>
<Datagrid>
<TextField source="id" />
<TextField source="slug" label="Years" />
<ReferenceManyField
reference="historyHospitals"
source="projectKey"
label="2019"
perPage={7}
allowEmpty={true}
>
<SingleFieldList>
<ChipField source="slug" />
</SingleFieldList>
</ReferenceManyField>
<EditButton />
</Datagrid>
</List>
);
抱歉,我已经找到解决方案好几次了 首先使用目标而不是源。 其次,将资源指向适当的路线(这里链接到主要路线的是医院)。 请注意,ReferenceManyField 基本上用于通过公共 属性 将主干道与其他道路连接起来(对于我来说,它是 projectKey,这是医院出现的主键) 确保 API returns id 像这个 id 而不是 _id 检查完以上所有内容后,我们的最终代码将如下所示:
export const HistoryHospitalListTest = props => (
<List title="Liste des Hôpitaux" {...props}>
<Datagrid>
<TextField source="id" />
<TextField source="slug" label="Years" />
<ReferenceManyField
reference="historyHospitals"
target="projectKey"
label="2019"
perPage={7}
allowEmpty={true}
>
<SingleFieldList>
<ChipField source="slug" />
</SingleFieldList>
</ReferenceManyField>
<EditButton />
</Datagrid>
</List>
);