首页 > 解决方案 > 获取以前链接到用户的角色

问题描述

我有一个我无法解决的问题,我想我是按照文件来的。

我想在编辑用户时获取分配的角色,例如,如果存在用户“Daniel”,该用户具有“管理员”和“编辑”角色。当我编辑该用户时,我想获得那些分配的角色。

我的代码是:

export const UserEdit = props => (
<Edit title={<RoleTitle />} {...props}>
    <SimpleForm validate={validateUserEdition}>
        <TextInput source="name" />
        <TextInput source="email" type="email" />
        <TextInput source="password" type="password" />
        <ReferenceInput label="Role" source="role" reference="role">
            <AutocompleteArrayInput source="id" {...props} />
        </ReferenceInput>
    </SimpleForm>
</Edit>
);

在检查我的 API 的地方添加端点格式:

获取到 /user/{user}/role

有人帮我吗?

标签: react-admin

解决方案


我仍然无法解决我的问题,我在管理员中拥有的资源是用户和角色,但我想有了这些资源,它们足以在两者之间建立关系。

同样,当我编辑用户时,我需要能够查看和编辑与其关联的角色。

我的代码如下

export const UserEdit = props => (
<Edit title={<RoleTitle />} {...props}>
    <SimpleForm validate={validateUserEdition}>
        <TextInput source="name" />
        <TextInput source="email" type="email" />
        <TextInput source="password" type="password" />
        <ReferenceInput label="Role" source="role" reference="role">
            <AutocompleteArrayInput source="id" {...props} />
        </ReferenceInput>
    </SimpleForm>
</Edit>
);

在 app.js 中

const App = ( ) => (
    <Admin dashboard={ Dashboard } dataProvider={ dataProvider } authProvider={ authProvider }>
        <Resource name="user" list={ UserList } create={ UserCreate } edit={ UserEdit } icon={ UserIcon }/>
        <Resource name="role" list={ RoleList } create={ RoleCreate } edit={ RoleEdit } icon={ ContactsIcon }/>
   </Admin>
);

感谢


推荐阅读