只允许在 edit/create 中创建新的 ArrayInput 元素并只允许创建现有元素 immutable/display

Only allow creation of new ArrayInput elements in edit/create & make existing ones immutable/display only

我已经阅读了一天的文档和论坛,但没有找到我的答案的解决方案。我想知道 react-admin.

是否可以实现以下内容

我有一个可以为其创建模板的资源文档。 模板的数量是无限的,但是一旦添加了模板,它就不能被编辑或移除。

当我编辑文档时,我可以编辑它的标题和描述或添加新模板,但我不能modify/delete旧模板。

例如看下图:

在标题、描述和创建日期下方有一个 ArrayInput 字段,其来源='templates'。

第一个条目对应于我已经创建的条目,但它是可变的。 底部是一个显示模板的简单数据网格。

我要么需要一个数据网格并且只能创建新模板,要么让 ArrayInput 中的现有条目不可变。

有没有一种干净的或 hacky 的方法来实现这个目标? 如果没有,它应该是 imo 的一个功能。你怎么看?

这是一个非常具体的用例,因此我们不会开箱即用地支持此功能。但是,如 documentation, the only child accepted by the ArrayInput is an implementation of an iterator which is the component responsible for allowing add/remove and displaying the inputs. We only provide the SimpleFormIterator but you can make your own based on its source.

中所述

我认为您可能需要一个接受两个渲染道具的迭代器组件,一个用于 return 字段的现有项目,另一个用于 return 输入的新项目。它会像这样使用:

<ArrayInput source="templates">
    <SimpleFormIterator
        renderExisting={() => ([
            <TextField source="country" />,
            <TextField source="templateId" />,
            <NumberField source="pages" />,
        ])}
        renderNew={() => ([
            <TextInput source="country" />,
            <TextInput source="templateId" />,
            <NumberInput source="pages" />,
        ])}
    />
</ArrayInput>