我尝试了两种方法:localStorage 或 query params,如您在代码中所见.但这些都不好,没有按预期工作(创建重定向等时查询参数丢失)有什么想法吗? 解决方案 你应该链接到一个过滤的列表,比如{localStorage.setItem('classId', record.id);历史推送({路径名:'学生',搜索:字符串化({页数:1,每页:25,排序:'createdOn',订单:'DESC',过滤器:{classId:record.id},}),})}}>这是在演示中完成的,参见https://github.com/marmelab/admin-on-rest-demo/blob/master/src/categories/LinkToRelatedProducts.jsVersion: Next (react-admin)Resources Classes and Students."Students" has a foreign key to "Classes": class_id.So, in the List of Classes we have for each row (class) a button "View/Edit Students of Class".When we click on this button, we have this code:<Button label={'View/Edit Students of Class'} onClick={(e) => { localStorage.setItem('classId', record.id); history.push({ pathname: 'students', search: stringify({ page: 1, perPage: 25, sort: 'createdOn', order: 'DESC', classId: record.id, }), }) }}>The idea is that we need somehow to get a 'classId' value in all CRUD operations of the 'Student', so that we filter by 'classId' in List and use this classId as a disabled field in CREATE.I tried 2 ways: localStorage or query params as you can see in the code.But these are not good, not working as expected (query params are lost when CREATE redirects, etc.)Any ideas? 解决方案 You should link to a filtered list, something like<Button label={'View/Edit Students of Class'} onClick={(e) => { localStorage.setItem('classId', record.id); history.push({ pathname: 'students', search: stringify({ page: 1, perPage: 25, sort: 'createdOn', order: 'DESC', filter: { classId: record.id }, }), }) }}>This is done in the demo, see https://github.com/marmelab/admin-on-rest-demo/blob/master/src/categories/LinkToRelatedProducts.js 这篇关于如何将资源的所有 CRUD 操作链接到特定外键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-15 09:25