在React-Admin仪表板上使用<List />

Tho*_*wax 7 react-admin

我正在使用带有自定义仪表板组件的react-admin v2.3.2,如react-admin教程中所示。

    <Admin dashboard={MyDashboard}>
       <Resource name="incidents ... />
    </Admin>
Run Code Online (Sandbox Code Playgroud)

现在,我想使用react-admin组件在仪表板上显示事件列表,但是react-admin抱怨缺少诸如“ hasEdit”之类的属性。

我只是将仪表板组件的props传递给List,但这显然不起作用:

    class MyDashboard extends React.Component    {
      constructor(props) {
      super(props)

      render(
        return <List {...this.props}>
          <Datagrid> .... </Datagrid>
        </List>

      )
    }
Run Code Online (Sandbox Code Playgroud)

是否可以<List />在仪表板上使用react-admin的组件,如果可以,该如何做?

预先感谢,托马斯

Tho*_*wax 8

我终于通过伪造所需的道具成功地使用了 react-admin 的组件。在 MyDashboard 组件中,我定义了组件所需的道具:

    let fakeProps = {
        basePath: "/incidents",
        hasCreate: false,
        hasEdit: false,
        hasList: true,
        hasShow: false,
        history: {},
        location: { pathname: "/", search: "", hash: "", state: undefined },
        match: { path: "/", url: "/", isExact: true, params: {} },
        options: {},
        permissions: null,
        resource: "incidents"
    }

    <List {...fakeProps}>
      <DataGrid>
        <TextField .... />
      </DataGrid>
    </List>
Run Code Online (Sandbox Code Playgroud)

这确实是一个次优解决方案,但在第一次运行时它解决了我的问题。