我正在实现一个管理工具网站,我正在使用材料的ui为此。我使用redux saga来处理异步调用(用于调用服务)。rest上的管理员有一些非常有用的组件,比如dataGrid。但是使用它们并不像我想的那么简单。最初,为了使用它,您应该将应用程序包装在Admin组件中,就像这样:
const App = () => (
<Admin restClient={simpleRestClient('http://path.to.my.api/')}>
<Resource name="posts" list={PostList} />
</Admin>
);根据我在文档中的理解,restClient属性是强制的。我想要使用前面提到的DataGrid组件,但是当我尝试使用它时,出现一个错误,显示在库的mapStateToPros函数中未定义资源。我一定是漏掉了什么很重要的东西。但是我发现仅仅使用外部库是非常复杂的。之前有人使用过这个库,并为我提供了一些帮助。我只需要使用数据网格。非常感谢
发布于 2017-11-23 16:20:33
Admin-on-rest不是一个UI库。它是一个管理框架,旨在作为一个整体使用。有很多React datagrids库。如果您不需要完整的Admin,请不要使用admin-on-rest
发布于 2017-11-23 16:21:44
如果您只需要Datagrid,只需使用Material UI中的Table组件即可。
发布于 2017-11-23 19:34:39
你确定你没有忘记从'admin-on-rest‘导入一些东西吗?
你的应用程序应该这样声明(一些代码遗漏了):
import React, { Component } from 'react';
import { jsonServerRestClient, Admin, Resource } from 'admin-on-rest';
const restClient = jsonServerRestClient('http://localhost:8000')
class App extends Component {
render() {
return (
<Admin restClient={restClient} >
<Resource name="vendors" list={VendorList} />
</Admin>
);
}
}VendorList应该像这样声明:
import React from 'react';
import { List, Datagrid, TextField } from 'admin-on-rest'
export const VendorList = (props) => (
<List {...props}>
<Datagrid>
<TextField source="id" />
<TextField source="name" />
<TextField source="description" />
</Datagrid>
</List>
);在这个例子中,它将是从http://localhost:8000/vendors获取数据,我在使用admin-on-rest时从来没有遇到过麻烦(可能只有在使用django-rest后端时才会遇到)。但一切都解决了。)
https://stackoverflow.com/questions/47450551
复制相似问题