react-admin - React admin导入按钮referenceManyField?
问题描述
我想为我的反应管理应用程序添加一个导入按钮。
此导入将创建与另一条记录相关的记录。例如,我有一份属于一家公司的合同清单。
我看到了这个仓库:https ://github.com/benwinding/react-admin-import-csv
我想知道referenceManyField是否有类似的东西。
解决方案
如果有人感兴趣,我为此找到了一个 hacky 解决方案。
我没有使用ReferenceManyField,而是在 Show 组件中使用了List 。
为了能够做到这一点,我必须覆盖列表的道具来指定我想要引用的资源。
我还必须将显示项目 id 作为列表组件的道具传递,并通过 id 过滤列表。
let companyId = '';
const ListActions = (props) => {
const { className } = props;
return (
<TopToolbar className={className}>
<ImportButton {...props} />
</TopToolbar>
);
};
export const ContractRow = ({ contractCompanyId }) => {
companyId = contractCompanyId;
const fakeProps: ListProps = {
basePath: '/contracts',
hasCreate: false,
hasEdit: false,
hasList: true,
hasShow: false,
location: { pathname: '/', search: '', hash: '', state: undefined },
match: { path: '/', url: '/', isExact: true, params: {} },
options: {},
permissions: null,
resource: 'contracts',
};
return (
<List
{...fakeProps}
filter={{ _company_id: contractCompanyId }}
actions={<ListActions />}
>
<Datagrid className={classes.insideTable}>
<TextField source="name" />
</Datagrid>
</List>
);
};
推荐阅读
- php - 我无法将我的数据库表连接到我的网站以进行注册和登录
- matomo - 如何将日志文件导入 Matomo?
- c# - 如何从非泛型方法分派到泛型处理程序?
- android - Android Studio 覆盖了整个项目
- kubernetes - 如何显式删除容器的 cpu 限制?
- c++ - QT QImage - 将图像的子部分复制为多边形
- python - 如何将张量的图像保存为 PNG?
- c# - Bot Framework - 找到机器人回答的问题以及用户对按钮做出反应的方法?
- linux - 如何调用已经运行的程序从 Perl 或 bash 脚本打开新文件?
- python - 税收计算器只打印原始输入而不是总数