javascript - 给 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
.
有什么想法我该怎么做?先感谢您。
解决方案
如果你想复制List
组件使用的 UIListController
和ListView
.
<ListController {...fakeProps}>
{({ data, ...controllerProps }) =>
return <ListView data={yourData} {...fakeProps} {...controllerProps}>
</ListView>
}
</ListController>
也有可能您必须转换要放入ListView
using的数据格式reduce
。
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce
此外,您可能需要提供ListView
更多自定义道具,只需检查控制台中的错误。
推荐阅读
- python - 如何在 Google Colab 上导入 plotly
- javascript - MongoDB 到 Elasticsearch 索引
- math - 概率乘法背后的逻辑是什么
- node.js - 安装 sqlite3 时 node-pre-gyp 出错
- python - python conda pystan,需要旧版本的 mpfr 库吗?
- python - 如何检查 Python 对象是否满足类型约束?
- c++ - 链表中的递归长度函数实现
- elixir - 为什么我的 Elixir Ecto 查询中出现“关键字查询表达式中的 :except_all 不受支持”?
- hibernate - org.hibernate.UnknownEntityTypeException: Unable to locate persister: com.entity.Employee ,我正在尝试做二级缓存
- pyspark - 将 pyspark 数据帧转换为动态数据帧