Admin-on-rest,编辑页面 - 不正确的元素错误
Admin-on-rest, Edit Page - Incorrect Element Error
我在前端使用 admin-on-rest。但是当我点击列表页面的编辑按钮时,它成功地定位到编辑页面但是总是出现"INCORRECT ELEMENT"这样的错误。你知道为什么吗?
谢谢
enter image description here
enter image description here
App.js
import { DataTypeList } from './Components/DataType/DataTypeList';
import { FeatureList } from './Components/FeatureList';
import { DataPointTypeList } from './Components/DataPointTypeList';
import DashBoard from './Components/DashBoard';
import { DataTypeCreate } from './Components/DataType/DataTypeCreate';
import { DataTypeEdit } from './Components/DataType/DataTypeEdit';
const httpClient = (url, options = {}) => {
if (!options.headers) {
options.headers = new Headers({ Accept: 'application/json' });
}
// add your own headers here
options.headers.set('X-Custom-Header', 'foobar');
return fetchUtils.fetchJson(url, options);
}
const restClient = jsonServerRestClient('http://localhost:3001/designer', httpClient);
const App = () => (
// <Admin title="GAMMA" dashboard={DashBoard} restClient={jsonServerRestClient('https://arcane-citadel-28609.herokuapp.com/designer')}>
<Admin title="GAMMA" dashboard={DashBoard} restClient={restClient}>
<Resource name="datatypes" list={DataTypeList} create={DataTypeCreate} edit={DataTypeEdit} />
<Resource name="features" list={FeatureList} />
<Resource name="datapointtypes" list={DataPointTypeList} />
</Admin>
);
export default App;
DataTypeEdit.js
import React from 'react';
import { Create, Edit, SimpleForm, TextInput } from 'admin-on-rest';
import { DataTypeActions } from '../Actions/DataTypeActions';
import { DataTypeEditActions } from '../Actions/DataTypeEditActions';
export const DataTypeEdit = (props) => (
<Edit title="Data Type - EDIT" actions={<DataTypeEditActions /> {...props}>
<SimpleForm>
<TextInput source="id" label="Name"/>
</SimpleForm>
</Edit>
);
DataTypeEditActions.js
import React from 'react';
import { CardActions } from 'material-ui/Card';
import FlatButton from 'material-ui/FlatButton';
import { DeleteButton, ListButton, RefreshButton, ShowButton, Edit } from 'admin-on-rest';
const cardActionStyle = {
zIndex: 2,
display: 'inline-block',
float: 'right',
};
export const DataTypeEditActions = ({ basePath, data }) => (
<CardActions style={cardActionStyle}>
<ListButton basePath={basePath} />
<DeleteButton basePath={basePath} record={data} />
<RefreshButton />
</CardActions>
)
问题是你的 json 数据,尝试 return { "id": "1", "name": "test", "type": "test" },不是数组。
如果结果的 ID 与请求的 ID 不匹配,也会出现此错误。
我在前端使用 admin-on-rest。但是当我点击列表页面的编辑按钮时,它成功地定位到编辑页面但是总是出现"INCORRECT ELEMENT"这样的错误。你知道为什么吗?
谢谢
enter image description here
enter image description here
App.js
import { DataTypeList } from './Components/DataType/DataTypeList';
import { FeatureList } from './Components/FeatureList';
import { DataPointTypeList } from './Components/DataPointTypeList';
import DashBoard from './Components/DashBoard';
import { DataTypeCreate } from './Components/DataType/DataTypeCreate';
import { DataTypeEdit } from './Components/DataType/DataTypeEdit';
const httpClient = (url, options = {}) => {
if (!options.headers) {
options.headers = new Headers({ Accept: 'application/json' });
}
// add your own headers here
options.headers.set('X-Custom-Header', 'foobar');
return fetchUtils.fetchJson(url, options);
}
const restClient = jsonServerRestClient('http://localhost:3001/designer', httpClient);
const App = () => (
// <Admin title="GAMMA" dashboard={DashBoard} restClient={jsonServerRestClient('https://arcane-citadel-28609.herokuapp.com/designer')}>
<Admin title="GAMMA" dashboard={DashBoard} restClient={restClient}>
<Resource name="datatypes" list={DataTypeList} create={DataTypeCreate} edit={DataTypeEdit} />
<Resource name="features" list={FeatureList} />
<Resource name="datapointtypes" list={DataPointTypeList} />
</Admin>
);
export default App;
DataTypeEdit.js
import React from 'react';
import { Create, Edit, SimpleForm, TextInput } from 'admin-on-rest';
import { DataTypeActions } from '../Actions/DataTypeActions';
import { DataTypeEditActions } from '../Actions/DataTypeEditActions';
export const DataTypeEdit = (props) => (
<Edit title="Data Type - EDIT" actions={<DataTypeEditActions /> {...props}>
<SimpleForm>
<TextInput source="id" label="Name"/>
</SimpleForm>
</Edit>
);
DataTypeEditActions.js
import React from 'react';
import { CardActions } from 'material-ui/Card';
import FlatButton from 'material-ui/FlatButton';
import { DeleteButton, ListButton, RefreshButton, ShowButton, Edit } from 'admin-on-rest';
const cardActionStyle = {
zIndex: 2,
display: 'inline-block',
float: 'right',
};
export const DataTypeEditActions = ({ basePath, data }) => (
<CardActions style={cardActionStyle}>
<ListButton basePath={basePath} />
<DeleteButton basePath={basePath} record={data} />
<RefreshButton />
</CardActions>
)
问题是你的 json 数据,尝试 return { "id": "1", "name": "test", "type": "test" },不是数组。
如果结果的 ID 与请求的 ID 不匹配,也会出现此错误。