【发布时间】:2018-03-11 09:28:00
【问题描述】:
我在站点设置面板中使用 AOR 1.2.2。 棘手的部分是这些设置可以有不同的类型:字符串、整数、布尔值、字符串数组、整数等 我设法通过从商店连接记录并使用以下代码来做到这一点:
const SettingsEdit = (props) => {
return (
<Edit actions={<SettingsEditActions {...props} />} title=
{<SettingsTitle />} {...props}>
<SimpleForm toolbar={<EditToolbar />}>
<TextField source="description" />
<DisabledInput elStyle={{ width: '100%' }} label="Default
value" source="defaultValue" />
{renderCountryValue(props)}
</SimpleForm>
</Edit>
);
};
const renderCountryValue = (prop) => {
const record = prop.record;
if (record) {
if (record.multilang) {
// countryValue will be a dict with locale keys
// TODO Multilang fields temporary disabled in restClient
return null;
}
// countryValue will be single value or array
if (record.schema.type === 'array') {
// countryValue will be single array
if (record.schema.items.type === 'string') {
return <LongTextInput format={v => v.join()} parse={v => v.split(',')} label="Value" source="countryValue" />;
}
if (record.schema.items.type === 'integer') {
return <LongTextInput format={v => v.join()} parse={v => v.split(',')} validate={validateIntegerArray} label="Value" source="countryValue" />;
}
}
// countryValue will be single value
if (record.schema.type === 'string') {
return <TextInput label="Value" source="countryValue" />;
}
if (record.schema.type === 'integer') {
return <NumberInput label="Value" source="countryValue" />;
}
if (record.schema.type === 'boolean') {
return <BooleanInput label="Value" source="countryValue" />;
}
return <LongTextInput label="Value" source="countryValue" />;
}
return <TextInput label="Value" source="countryValue" />;
};
在我尝试将 AOR 更新到 1.3.1 之前它运行良好,然后它停止了。 我注意到的是,在第一次渲染中没有记录,因此它呈现默认的 TextInput 但在第二次渲染时,当有记录时,它不会将此输入重新渲染为正确的类型,如 NumberInput 等。 我试图调试它,程序在它应该呈现其他输入但屏幕上没有任何反应时出现。 有什么想法或解决方法吗?
【问题讨论】:
标签: javascript reactjs renderer admin-on-rest