react-admin - 获取以前链接到用户的角色
问题描述
我有一个我无法解决的问题,我想我是按照文件来的。
我想在编辑用户时获取分配的角色,例如,如果存在用户“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
有人帮我吗?
解决方案
我仍然无法解决我的问题,我在管理员中拥有的资源是用户和角色,但我想有了这些资源,它们足以在两者之间建立关系。
同样,当我编辑用户时,我需要能够查看和编辑与其关联的角色。
我的代码如下
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>
);
感谢
推荐阅读
- c++ - C++ OpenCv (-215: Assertion Error) !_src.empty() in function 'cvtColor'
- xamarin - Xamarin:如何在 Android 上获取 AdvertisingId?
- c# - 如何绑定 HTML 元素通过 C# 中的 WebBrowser 控件导航
- javascript - 笑话单元测试:setTimeout 未在异步测试中触发
- php - PHP MYSQL 跳过结果
- java - 我如何在 Android 中使用 findViewById()?
- django - Django + Plesk + Apache - 在某些 url 上禁止 403 但 404 的显示应用程序正在运行...?
- cluster-computing - sqoop 作业数据也存储在 edgenode 和 namenode 中
- javascript - 拆分条 (Splitter) 未显示。仅在鼠标悬停时,拆分器才会显示
- java - 简单的 GridLayout 缩放动画