0

有没有办法在显示显示页面之前做一个 if 语句?例如,如果我使用显示按钮单击的元素的 id 以“.log”结尾,我希望显示页面如下所示:

export const reportShow = ({ ...props }) => (
<Show title="Log" {...props}>
    <SimpleShowLayout>
        <ReferenceManyField label="Log" reference="archivedfiles" target="id">
            <Datagrid>
                <TextField source="id" label="Line" />
                <TextField source="timestamp" label="Timestamp" />
                <TextField source="severity" label="Severity" />
                <TextField source="message" label="Message" />
            </Datagrid>
        </ReferenceManyField>
    </SimpleShowLayout>
</Show>);

但是,如果 id 以 .txt 结尾,我希望显示页面显示一个报告页面,该页面将包含以下内容:

export const reportShow = ({ ...props }) => (
<Show title="Report" {...props}>
    <SimpleShowLayout>
                <TextField source="id" label="Report Name" />
                <TextField source="rmessage" label="Message" />
    </SimpleShowLayout>
</Show>);

解决此问题的最佳方法是什么?

4

2 回答 2

0

Maybe the aor-dependent-input addon can help you with that.

于 2017-05-25T16:58:21.097 回答
0

我最终通过这样做使这个工作:

export const archivedShow = ({ ...props }) => {
    if (props.match.params.id.endsWith("txt")){
    return (<Show title="Report" {...props}>
        <SimpleShowLayout>
            <ReferenceManyField label="Report" reference="archivedfiles" target="id">
                <Datagrid>
                    <FormattedReportView/>
                </Datagrid>
            </ReferenceManyField>
        </SimpleShowLayout>
    </Show>
    );
    }
    else {
        return (
        <Show title="Log" {...props} filters={< LogFilter/>}>
            <SimpleShowLayout>
            <ReferenceManyField label="Log" reference="archivedfiles" target="id">
                <Datagrid>
                    <TextField source="id" label="Line" />
                    <TextField source="timestamp" label="Timestamp" />
                    <TextField source="severity" label="Severity" />
                    <TextField source="message" label="Message" />
                </Datagrid>
            </ReferenceManyField>
        </SimpleShowLayout>
        </Show>
        );
    }
}
于 2017-05-26T16:13:28.950 回答