我有一个非常简单的用户列表,带有 Admin On Rest(版本 1.1.0)。
<Admin authClient={authClient} restClient={restClient}>
<Resource name="users" list={UsersList} edit={UsersEdit} />
</Admin>
这将执行一个 GET 请求https://example.com/api/users?_sort=id&_order=DESC&_start=0&_end=25
,我返回一个用户列表,其中包含仅用于呈现列表所需的数据。
当我编辑其中一个用户时,会执行 GET 请求以获取该特定用户的所有数据https://example.com/api/users/3ba7141c-03d2-4234-9031-76bf88ca7454
。
但是,由于某种原因,获取的数据存储在 Redux 存储中的未定义字段中:
{
admin: {
users: {
data: {
3ba7141c-03d2-4234-9031-76bf88ca7454: {
// data returned from /users
},
undefined: {
// data fetched from /users/3ba7141c-03d2-4234-9031-76bf88ca7454
}
}
}
}
}
由于这个错误,我无法正确呈现我的表单:
<Edit title="Edit" {...props}>
<SimpleForm>
{/*
this one renders correctly as the Id is present in the `/users` request
*/}
<DisabledInput label="Id" source="id" />
{/*
this one renders no content as it cannot find the new data from `/users/3ba...`
(probably because of the undefined in the store)
*/}
<TextInput label="email" source="account.email" validate={required} />
</SimpleForm>
</Edit>
这是我可能错过了一些配置的库中的错误吗?
注意:这是我正在使用的其余客户端定义(文档中的代码)
const httpClient = (url, options = {}) => {
if (!options.headers) {
options.headers = new Headers({ Accept: 'application/json' });
}
const token = localStorage.getItem('token');
options.headers.set('Authorization', `Bearer ${token}`);
return fetchUtils.fetchJson(url, options);
}
const restClient = jsonServerRestClient('https://example.com/api', httpClient);