Reactjs 当<;编辑>;来自<;列表>;
我有一个非常简单的用户列表,其中包含Rest上的Admin(版本1.1.0) 由于此错误,我无法正确呈现我的表单:Reactjs 当<;编辑>;来自<;列表>;,reactjs,react-redux,admin-on-rest,Reactjs,React Redux,Admin On Rest,我有一个非常简单的用户列表,其中包含Rest上的Admin(版本1.1.0) 由于此错误,我无法正确呈现我的表单: <Edit title="Edit" {...props}> <SimpleForm> {/* this one renders correctly as the Id is present in the `/users` request */} <DisabledInput label="Id" source
<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>
我认为获取的数据没有
id
字段。您可以通过检查redux商店的此部分来验证这一点:
{
admin: {
users: {
data: {
3ba7141c-03d2-4234-9031-76bf88ca7454: {
// data returned from /users
},
undefined: {
// data fetched from /users/3ba7141c-03d2-4234-9031-76bf88ca7454
}
}
}
}
}
undefined: {
// data fetched from /users/3ba7141c-03d2-4234-9031-76bf88ca7454
}
您可以通过添加
id
字段从后端修复它。嗨,wesley6j,我正在使用jsonServerRestClient。我刚刚尝试了一个具有数字id(例如666)的用户,但它具有相同的行为(未定义的属性仍在存储中)。我已经更新到新版本的admin on rest(1.1.0),没有luck@gyss我已根据您提供的信息更新了答案。您还可以将后端的数据与进行比较。该演示将所有请求/响应记录在控制台中,因此它应该会对您有所帮助。太棒了!这就是问题所在
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);
undefined: {
// data fetched from /users/3ba7141c-03d2-4234-9031-76bf88ca7454
}