TextField没有出现在“显示视图”中

时间:2019-05-01 16:04:50

标签: reactjs react-admin

我在Show视图中有一些TextField数据,我必须有条件地对其进行标记。我为此写了这个const:

const DataShow = ({record}) => {
    var label1, command;
    if ( parseInt(record.type) === 0 || parseInt(record.type) === 11 ) {
        label1 = "THM";
    }
    else if ( parseInt(record.type) === 21 ) {
        label1 = "Kártya típusa";
    }
    else if ( parseInt(record.type) === 26 ) {
        label1 = "EBKM";
    }
    else if ( parseInt(record.type) === 32 ) {
        label1 = "Számlavezetési díj";
    }
    else if ( parseInt(record.type) === 37 ) {
        label1 = "Minimum összeg";
    }
    else if ( parseInt(record.type) === 38 ) {
        label1 = "THM";
    }
    else if ( parseInt(record.type) === 47 ) {
        label1 = "Futamidő";
    }
    else {
        label1 = "";
    }
    command = <TextField source="data_1" label={label1} />;
    console.log("type: ", parseInt(record.type), "data_1: ", record.data_1, "label: ", label1, "command: ", command)
    return ( command );
};

我的问题是,即使我在控制台上找到调试信息,由于某种原因,返回也不起作用(“显示”视图中根本没有出现该字段)

我的显示代码:

export const AdShow = ({...props}) => (
    <Show {...props}>
        <TabbedShowLayout>
                <Tab label="summary">
                    <TextField label="Azonosito" source="id" />
                    <ReferenceField label="Hirdeto" source="user" reference="users">
                        <TextField source="name" />
                    </ReferenceField>
                    <TextField label="Termek Neve" source="title" />
                    {<AdStatus />}
                    {<DataShow />}
                    <SelectField label="Status" source="status" choices={[
                        {status: 0, name: "elfogadasra var" },
                        {status: 1, name: "aktiv" },
                        {status: 2, name: "inaktiv" },
                        {status: 3, name: "archiv" },
                    ]} optionText="name" optionValue="status" />
                    <SelectField source="click_type" choices={[
                        { id: 0, name: "CT Hirdetes"},
                        { id: 1, name: "Lead Hirdetes"},
                    ]} optionText="name" optionValue="id" />
                    <DateField label="Letrehozas datuma" source="time" />
                </Tab>
                <Tab label="Jellemzok">
                    <ReferenceField label="Tipus" source="type" reference="categories" >
                        <TextField source="name" />
                    </ReferenceField>
                    <ArrayField source="categories">
                        <SingleFieldList>
                            <ChipField source="name" />
                        </SingleFieldList>
                    </ArrayField>
                    <TextField label="data1" source="data_1" />
                    <TextField label="Kiegeszito adat" source="data_2" />
                    <TextField label="data2" source="data_3" />
                    <TextField label="Kiegeszito adat" source="data_4" />
                    <TextField label="data3" source="data_5" />
                    <TextField label="Kiegeszito adat" source="data_6" />
                    <TextField source="spec_1" label="Termek Jellemzok 1" />
                    <TextField source="spec_2" label="Termek Jellemzok 2" />
                    <TextField source="spec_3" label="Termek Jellemzok 3" />
                    <TextField source="spec_4" label="Termek Jellemzok 4" />
                    <TextField source="spec_5" label="Termek Jellemzok 5" />
                </Tab>
                <Tab label="Jogi es Igenylesi Feltetelek">
                    <RichTextField source="description" label="Jogi Feltetelek" />
                    <RichTextField source="conditions" label="Igenylesi Feltetelek" />
                    <TextField label="Kiemelt kep (URL)" source="image" />
                </Tab>
                <Tab label="Promocio">
                    <DateField source="start_time" label="Idozitett indulas" />
                    <DateField source="end_time" label="Idozitett leallitas" />
                </Tab>
                <Tab label="SiteAds">
                    <ArrayField source="siteads" addLabel={false} >
                        <Datagrid>
                            <ReferenceField label="Hirdeto Oldal" source="site_id" reference="sites">
                                <TextField source="name" />
                            </ReferenceField>
                            <UrlField label="Hivatkozas" source="href" />
                            <UrlField label="Visszahivas URL" source="href_call" />
                        </Datagrid>
                    </ArrayField>
                </Tab>
            </TabbedShowLayout>
    </Show>
);

我的const我该怎么做?

在devTools控制台上没有任何错误。

1 个答案:

答案 0 :(得分:0)

与此同时,我发现了这个问题:

返回时,TextField不知道该记录,因此我不得不明确告诉它record = {record}

<TextField record={record} source="data_1" label={label1} />