React-Admin获取列表数据提供程序

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

我开始使用“ React-Admin”软件包。因为我想使用另一个“资源”的数据进行“选择”,所以我无法进行开发。这就是为什么我使用“参考字段”,但我不知道为什么使用此元素会出现此错误。

我的错误是“对'GET_LIST'的响应必须类似于{data:[{id:123,...},...]},但是至少一个接收到的数据项没有'id'键。dataProvider对于“ GET_LIST”可能是错误的“”

以下是我从API收到的数据:[{"_id":"5e3ec3baa6480d002b24ea90","name_promo":"test","years":"2019-01-01T00:00:00.000Z","__v":0}]

有关信息,我使用提供程序“ ra-data-json-server”

这是我的代码:

import {
    Create,
    SimpleForm,
    TextInput,
    ReferenceInput,
    SelectInput,
} from 'react-admin';

const CreateUser = (props) => (
    <Create {...props}>
        <SimpleForm>
            <TextInput source="lastName" label="Prénom" />
            <TextInput source="firstName" label="Nom" />
            <TextInput source="email" label="Email" />
            <TextInput source="role" label="Role" />
            <ReferenceInput  label="Session" source="id" reference="sessions"  >
                <SelectInput optionText="name_promo"/>
            </ReferenceInput >
        </SimpleForm>
    </Create>
);

export default CreateUser;```
reactjs react-admin
1个回答
0
投票

您的数据是从API返回的,其ID字段名为"_id",而不是必需的"id"。您可以在DataProvider或API中对此进行修改。

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