我使用 ArrayInput 如下。我之前没有意识到这个组件。
<SelectInput source='type'
choices={[
{ name: 'String', id: 'string' },
{ name: 'Enum', id: 'enum' },
{ name: 'Decimal', id: 'decimal' }
]}
onChange={event => {
const type = Object.values(event).slice(0, -1).join('');
this.setState({
listEditorVisible: type === 'enum',
regexEditorVisible: type === 'string',
decimalEditorVisible: type === 'decimal'
});
}}
/>
{this.state.listEditorVisible ?
<ArrayInput source='values'>
<SimpleFormIterator>
<TextInput source='name' />
</SimpleFormIterator>
</ArrayInput>
:
null}
{this.state.decimalEditorVisible ?
<div>
<NumberInput source="min" /><br />
<NumberInput source="max" /><br />
<NumberInput source="res" /><br />
<TextInput source="unit" />
</div>
:
null}