简体   繁体   English

如何使用 ArrayInput 在 react-admin 列表视图中填充数据

[英]How to use ArrayInput to populate data in react-admin list view

I have a react-admin Create View that I want to display and populate using ArrayInput which however seems to ignore the data of the list.我有一个react-admin Create视图,我想使用ArrayInput显示和填充它,但它似乎忽略了列表的数据。

I tried to load the data with我试图加载数据

const { data } = useQueryWithStore({
    type: 'getList',
    resource: 'comments',
});

and to set the source to it manually, but the ArrayInput seems unimpressed by all efforts to feed it some data.并手动设置源,但ArrayInput似乎对所有向它提供一些数据的努力不感兴趣。

I can iterate through the data array and render TextFields and remove buttons accordingly, while leaving the ArrayInput for adding new data, but that defeats the purpose and the beautiful interaction with ArrayInput .我可以遍历数据数组并渲染TextFields并相应地删除按钮,同时让ArrayInput添加新数据,但这违背了目的和与ArrayInput的美妙交互。 Is there something I'm missing?有什么我想念的吗? How should I pass the data for it to work as one would expect?我应该如何传递数据以使其按预期工作? I made a sandbox example for this HERE我为此制作了一个沙盒示例HERE

For creating multiple rows of the entity with one form submit you will need a custom implementation or a work-around.要使用一个form提交创建多行实体,您将需要自定义实现或解决方法。

One of the most esiest ways could be to handle manually the submission of the form and alter the data and send separate requests for each entered entity.最简单的方法之一可能是手动处理表单的提交并更改数据并为每个输入的实体发送单独的请求。

Here in the docs is shown an example how you can pass the Create view a custom toolbar where you can implement your logic.文档中的此处显示了一个示例,您可以如何将Create视图传递给自定义toolbar ,您可以在其中实现您的逻辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM