我使用Show
顯示學生頁面。在學生頁面上,我想顯示許多課程的列表,並且列表必須分頁。如何使用Admin On Rest將動態過濾器傳遞給List組件?
export const StudentShow = (props) => (
<Show title='Student' {...props}>
<SimpleShowLayout>
// correctly displays the student ID
<TextField label='id' source='id' />
<ReferenceManyField
label='Courses'
target='course'
id='student.id'
reference='courses'>
// how can I properly pass the student ID to List?
<List {...props} filter={{ student: student.id }}>
<Datagrid>
<TextField source='code' />
</Datagrid>
</List>
</ReferenceManyField>
</SimpleShowLayout>
</Show>
);
的ReferenceManyField
正確地進行API調用來/courses/?student=<studentId>
,但是List
只是讓到/courses/
通話。我無法將學生ID傳遞給List
組件。
如何將學生ID傳遞給List
組件?
我不想在本地存儲中存儲任意值。你是正確的名單並不意味着是ReferenceManyField的子組件。我選擇了名單的原因是使用內置的分頁,其中的DataGrid沒有(https://github.com/marmelab/admin-on-rest/issues/561) – mcranston18
如果學生ID不是ID當前登錄的學生,那麼你不應該存儲它。 列表過濾器可以通過過濾器prop拍攝的操作進行更改。 https://marmelab.com/admin-on-rest/List.html#filters 根據當前的學生ID,您可以嘗試連接一直處於開啓狀態的默認過濾器。 –
這很有趣。你知道,如果它可以設置使用列表過濾器組件永久/默認篩選器? – mcranston18