reactjs - 带有状态记录的 admin-on-rest 提要
问题描述
我有一个 DisabledInput 像
<DisabledInput source="values" />
但我想为这个字段提供一个状态变量。因为这个状态变量可以随着用户交互而改变。更准确地说,在页面上,有一个列表框,当用户向该列表框添加新值时,“值”状态变量会发生如下变化
“item1,item2,item3 ...”,我想将此状态变量作为数据提供给 DisabledInput
this.state.values
我不知道该怎么做。也许有如下方法,但我做不到
<DisabledInput source="values" record={this.state.values} />
可能吗?
解决方案
我使用 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}
推荐阅读
- azure-devops - VSTS 历史查询
- docker - 通过命令行安装 julia 包
- sql - 如何从表名查询中获取选择计数(x)
- abcpdf - 使用 ABCPDF 将另一个文档绘制为带圆角的图像
- react-native - 在反应原生应用程序中使用 styleguidist
- docker - .NET Core API 502 带有 Nginx 代理的 Docker 上的错误网关
- javascript - 知道表单 POST 目标是否生成错误的任何方法
- cmake - CMake:add_subdirectory 两次作为共享项目
- json - Swift 4 解析 1+n 数量的 json 数字键
- java - 使用浮点变量在 Android 应用程序中显示板球比赛