首页 > 解决方案 > 给 List 组件特定的数据来显示

问题描述

我正在使用react-admin框架(3.2)。我有一个对象存储按过期过滤的实体。我想在List. 到目前为止,我已经尝试创建假道具来复制List组件。

let fakeProps = {
            basePath: basePath,
            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: resource,
            perPage: 30,
            actions: null,
            data: this.state.filteredList
        }

然后我用道具返回我的清单:

<List {...fakeProps}>
   <Datagrid>
      <TextField source='_id' />
   </Datagrid>
</List>

但我只得到每一个实体。我需要显示存储在this.state.filteredList.

有什么想法我该怎么做?先感谢您。

标签: javascriptreactjsreact-admin

解决方案


如果你想复制List组件使用的 UIListControllerListView.

<ListController {...fakeProps}>
  {({ data, ...controllerProps }) =>
    return <ListView data={yourData} {...fakeProps} {...controllerProps}>
    
    </ListView>
  }
</ListController>

也有可能您必须转换要放入ListViewusing的数据格式reduce

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce

此外,您可能需要提供ListView更多自定义道具,只需检查控制台中的错误。


推荐阅读