我有一个我无法解决的问题,我想我会按照信函中的说明去做。
我想在即时编辑用户时获得分配的角色,例如,如果存在具有“管理员”和“编辑”角色的用户“ 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
的意思是:
您必须为参考资源添加一个-react-admin需要它来获取参考数据。
因此,在您的情况下,<Admin/>
组件至少应具有这些:
<Admin dataProvider={myDataProvider}>
<Resource name="users" /> // endpoint that handles user records
<Resource name="roles" /> // endpoint that handles user ROLES records
</Admin>
不知道您如何使用此端点/user/{user}/role
,但显然不会执行您想要的操作。 Further reading here should help特别关注添加到Reference*
组件中的notes。
我仍然无法解决我的问题,我在管理员中拥有的资源是用户和角色,但是我想,有了这些资源,它们足以在两者之间建立关系。
同样,当我编辑用户时,我需要能够查看和编辑与之相关的角色。
我的代码如下
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> );
谢谢