首页 > 解决方案 > 在编辑输入中加载嵌套资源属性值

问题描述

我正在使用 React Admin 为我的 API 生成 CRUD。

在我的 API 中,我有一个资源 Person,其中包含一对一关系上的嵌套资源配置文件。创建和编辑人员时,我的 API 允许直接发送个人资料的属性,并创建或编辑嵌套的个人资料资源。

这是我GET对一个人执行 a 时收到的内容,也是我执行 a PUTor时可以发送到我的 API 的内容POST

person: {
    profile: {
        firstName,
        lastName
   },
   ...otherPersonProperties
}

在资源 Person 的 Edit 页面上,我显示了与配置文件嵌套资源相关的输入字段:

<Edit {...props}>
    <SimpleForm>
       <TextInput source="profile.firstName" {...props} />
       <TextInput source="profile.lastName" {...props} />
    </SimpleForm>
</Edit>

我本来希望与嵌套资源配置文件相关的文本输入预填充获取的值,但输入为空。

是否无法将嵌套资源属性的值加载到 TextInput 中?

编辑

这就是 fetch 带给我的:

@context: "/api/contexts/Person"
@id: "/api/persons/1004"
@type: "Person"
user: "/api/users/28"
profile: {
    @id: "/api/profiles/1004"
    @type: "Profile"
    firstName: "trainee2_firstName"
    lastName: "trainee2_lastname"
}

但这就是 formData 里面的内容:

@context: "/api/contexts/Person"
@id: "/api/persons/1002"
@type: "Person"
id: "/api/persons/1002"
user: "/api/users/28"
profile: "/api/profiles/1002"

似乎 React Admin 不明白我希望将配置文件字段值注入表单中。

标签: reactjsreact-adminapi-platform.com

解决方案


推荐阅读