【问题标题】:CheckboxGroupInput is not showing previous saved checkboxesCheckboxGroupInput 未显示以前保存的复选框
【发布时间】:2020-05-12 12:11:31
【问题描述】:

当我编辑一个项目时,我想获得之前选中的引用选项。选项显示得很好,但始终未选中。不过,它会保存我所做的任何更改。

它与 CheckboxGroupInput 以及 AutocompleteArrayInput 的工作方式相同。

ReferenceArrayInput 正在将此数组数据发送到 CheckboxGroupInput:

0: {id: 1, company-name: "Empresa 1", created_at: "2019-08-09T18:08:18.066Z", updated_at: "2019-08-28T13:17:02.474Z", …} 1: {id: 3, company-name: "Empresa 3", created_at: "2019-08-23T12:41:15.254Z", updated_at: "2019-08-23T12:41:15.528Z", …} 2: {id: 5, company-name: "Empresa 5", created_at: "2019-08-23T12:41:31.762Z", updated_at: "2019-08-23T12:41:32.013Z", …}

这是代码:

<SimpleForm>
  <TextInput source="game-name" label="Name" />
  <ReferenceArrayInput
    source="companies"
    reference="companies">
    <CheckboxGroupInput translateChoice={false} optionText="company-name"/>
  </ReferenceArrayInput>
</SimpleForm>

现在我收到了这条消息:“至少有一个关联的引用似乎不再可用。”表格下方。控制台没有显示任何错误。

【问题讨论】:

    标签: react-admin


    【解决方案1】:

    我相信我遇到了与您类似的问题,但我能够解决。试试这个。

    <ReferenceArrayInput
        source="company_ids"
        defaultValue={[]}
        reference="companies">
        <CheckboxGroupInput translateChoice={false} optionText="company-name"/>
    </ReferenceArrayInput>
    

    React-admin 需要 ReferenceArrayInput 从请求资源的数据响应中的 id 数组中获取参考数据。您需要将源更改为“company_ids”并确保资源在响应中返回该数据。

    现在是关于显示以前保存的数据的主要问题;我最初很难从我的数据库中获取数据来填充输入。我可以通过将一个空数组传递给 defaultValue 来使其工作。

    希望这会有所帮助。祝你好运!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-14
      相关资源
      最近更新 更多