my friends. want add field associated resource here: https://marmelab.com/admin-on-rest/tutorial.html#relationships
but problem field id of other resource contain in object:
{ "id": 1, ...., user: { id: "12313123" } }
what can in situation? understand can create own "filelds", how can create own "referencefield"? need "source" property contain this:
<referencefield label="user" source="user.id" reference="users"> <textfield source="name" /> </referencefield>
i'm not familiar admin-on-rest
framework, documentation seems possibly create custom textfield relatively simply. maybe similar thing creating custom referencefield.
import 'lodash.get'; // safe access of nested data const postuserfield = ({record}) => { // "record" post object in example return ( <referencefield label="user" source={ get('user.id', record) } reference="users"> <textfield source="name" /> </referencefield> ); }
and call
// inside other component.. <postuserfield />
if doesn't work, try see if overwrite record
prop in custom component, access no longer nested. in contex, id
point same property user.id
.
const postuserfield = ({record}) => { // "record" post object in example // prepare record reference field, removing // nesting const unnesteduser = record.user; return ( <referencefield record={ unnesteduser } label="user" source="id" reference="users"> <textfield source="name" /> </referencefield> ); }
actually, @ problem again.. sure need referencefield
fetch user id (user.id)? because post seem have user data. solve custom textfield like:
import 'lodash.get'; // "record" still post object. since data on // post object (in user.name) , can print directly const postusername = ({record }) => <span>{get(record, 'user.name')}</span>;
Comments
Post a Comment