I'm starting to use the react-admin
package.
I am blocked in my development because I would like to make a Select
with the data of another Resource
. And that's why I use ReferenceField
but I don't know why I get this error when I use this element.
Error: The response to 'GET_LIST' must be like { data : [{ id: 123, ...}, ...] }, but at least one received data item do not have an 'id' key. The dataProvider is probably wrong for 'GET_LIST
Here is the data that I receive from my API:
[{"_id":"5e3ec3baa6480d002b24ea90","name_promo":"test","years":"2019-01-01T00:00:00.000Z","__v":0}]
For information, I use the Provider ra-data-json-server
Here is my code:
import React from 'react';
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;
Your data is being returned from the API with its id field named "_id"
instead of the required "id"
.
We solved this problem by adding the following to our (python) API.
myData = mongo.get(...)
for x in myData:
x['id'] = x['_id'] // Now each record has both '_id' and 'id'
return {'data': myData}, HTTPStatus.CREATED
ra-admin by default use the keys id and name , if your API call is not returning that firm you must declare it as a prop on the component
<ReferenceInput label="Session" source="id" reference="sessions" >
<SelectInput optionText="name_promo" optionValue="_id" />
</ReferenceInput>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.