在ArrayInput / SimpleFormIterator中使用ReferenceField

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

正如标题所述。我需要在ArrayInput / SimpleFormIterator内使用ReferenceField。我不断收到以下错误:

TypeError: Cannot read property 'replace' of undefined

版本:

react-admin: 3.2.3
react: 16.12.0

这里是代码段:

<ArrayInput source="specialties" label="">
  <SimpleFormIterator disableAdd>
    <ReferenceField label="Specialties Link" source="ID" reference="specialty" link="show" >
      <TextField source="ID" />
    </ReferenceField>
    <TextInput source="vendorSpecialtyText" label="Vendor Specialty Text" />
  </SimpleFormIterator>
</ArrayInput>

[有一个名为specialty的资源,它可以在应用程序其他部分的ArrayField内部工作,如下所示:

<ArrayField source="specialties" label=" Specialties">
  <SingleFieldList>
    <ReferenceField label="Specialties Link" source="ID" reference="specialty" link="show" >
      <TextField source="ID" />
    </ReferenceField>
  </SingleFieldList>
</ArrayField>

不确定在此框架内是否无法做到这一点,或者我是否实现了此错误。如果有解决此问题的方法,或者有其他解决方案,请告诉我!谢谢。

react-admin
1个回答
0
投票

From the documentation

注意: SimpleFormIterator仅接受Input组件作为子组件。如果要改用Fields,则必须使用<FormDataConsumer>来获取正确的源,...“”>

import { ArrayInput, SimpleFormIterator, DateInput, TextInput, FormDataConsumer } from 'react-admin';

<ArrayInput source="backlinks">
    <SimpleFormIterator disableRemove >
        <DateInput source="date" />
        <FormDataConsumer>
            {({ getSource, scopedFormData }) => {
                return (
                    <TextField
                        source={getSource('url')}
                        record={scopedFormData}
                    />
                );
            }}
        </FormDataConsumer>
    </SimpleFormIterator>
</ArrayInput>

或包括输入字段

<ArrayInput source="specialties" label="">
  <SimpleFormIterator disableAdd>
    <ReferenceInput label="Specialties Link" source="ID" reference="specialty">
      <SelectInput optionText="{Your description field}"  />
    </ReferenceInput>
    <TextInput source="vendorSpecialtyText" label="Vendor Specialty Text" />
  </SimpleFormIterator>
</ArrayInput>
© www.soinside.com 2019 - 2024. All rights reserved.