【问题标题】:how to use ReferenceManyField?如何使用 ReferenceManyField?
【发布时间】:2019-11-27 11:49:34
【问题描述】:

ReferenceManyField 的目标属性不能使用 react-admin 运行。
我尊重文档中给出的逻辑。我什至确保我提供的数据具有没有子轨道的 id,因为我使用数据库 mongo db(其中标识符具有这种形式 _id)。简而言之,ReferenceManyField 将所有数据返回给我,而不考虑目标属性

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 发送的 API 请求是什么样的?

标签: react-admin


【解决方案1】:

对不起,我已经找到了解决方案,因为 首先使用目标而不是源。 其次,将资源指向适当的路线(这里与主要路线相连的是医院)。 请注意,ReferenceManyField 基本上用于通过公共属性将主要道路与其他道路连接起来(在我的情况下,它是 projectKey,它是医院发生的主键) 确保 API 返回类似此 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>
);

【讨论】:

    猜你喜欢
    • 2023-03-19
    • 1970-01-01
    • 2019-09-14
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 2018-08-12
    • 2018-01-21
    • 1970-01-01
    相关资源
    最近更新 更多