【问题标题】:admin-on-rest feed with state record带有状态记录的 admin-on-rest 提要
【发布时间】:2018-05-22 07:11:46
【问题描述】:

我有一个像

这样的 DisabledInput
<DisabledInput source="values" />

但我想为这个字段提供一个状态变量。因为这个状态变量可以随着用户交互而改变。更准确地说,在页面上,有一个列表框,当用户向该列表框添加新值时,“值”状态变量会像

"item1, item2, item3..." 我想将此状态变量作为数据提供给 DisabledInput

this.state.values

我不知道该怎么做。也许有如下方法,但我做不到

<DisabledInput source="values" record={this.state.values} />

有可能吗?

【问题讨论】:

  • 你可以制作一个代码框来显示你已经尝试过的内容吗?
  • codesandbox.io/s/nno0kon4qm我在帖子中提到的文件是ListEditor.js
  • 你可以让它可用吗?
  • 我的 REST Api 在我的本地工作,所以我不能这样做,我已经用另一种方式解决了这个问题。谢谢
  • 我使用 ArrayInput 如下。我之前没有意识到这个组件。 {this.state.listEditorVisible ? : null}

标签: reactjs admin-on-rest react-admin


【解决方案1】:

我使用 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}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-19
    • 1970-01-01
    • 1970-01-01
    • 2018-01-07
    • 1970-01-01
    相关资源
    最近更新 更多