我有一个Edit组件,我将其转换为一个类,如下所示:
<Edit {...this.props} >
<SimpleForm
toolbar={null}
>
<TextField source='email'/>
<ArrayField source='allComponents'>
<Datagrid>
<TextField label='ID' source='id'/>
<TextField label='Component Name' source='name'/>
<RadioButtons label='Access'
source='value'
onChange={this.handleChange}
value={this.props.record.value}
name={this.props.record.name}
/>
</Datagrid>
</ArrayField>
<SaveButton onClick={this.handleSubmit}/>
</SimpleForm>
</Edit>我还有一个名为RadioButtons的组件,如下所示:
export const RadioButtons = ({ handleChange }) => {
const { value, name } = this.props
return <FormControl>
<RadioGroup row value={value.toString()} name={name.toString()}>
{choices.map(c => <FormControlLabel
control={<Radio/>}
label={c.name}
key={c.id}
value={c.value}
style={{ flexDirection: 'column-reverse', padding: '10px 20px' }}
onChange={handleChange}
/>
)}
</RadioGroup>
</FormControl>
}Edit组件呈现与我单击的用户相关的组件列表。该列表中的每个组件都有3个单选按钮,可能有3个值,它呈现choices数组:
const choices = [
{ id: '1', name: 'no access', value: '0' },
{ id: '2', name: 'read access', value: '1' },
{ id: '3', name: 'full access', value: '2' }
]我试图传递到RadioButtons输入值,它是一个不同的组件反应-管理员的单选按钮。
我怎么能这么做?通常是source='value',但这不是react的组件。另外,当尝试访问记录对象时,它似乎不存在于this.props.record中(它是未定义的)。
发布于 2020-07-15 06:10:16
根据https://marmelab.com/react-admin/Fields.html
记录:包含要显示的属性的对象。,以及其他组件向他们的孩子注入该道具。
因此,只要您的组件被包装在DataGrid中,就像它在这里一样,您就应该是正确的。但你也需要像这样去记录:
export = ({ handleChange,record }) => {
https://stackoverflow.com/questions/62260166
复制相似问题