【问题标题】:Admin-On-Rest Customizing InputsAdmin-On-Rest 自定义输入
【发布时间】:2017-09-29 15:43:51
【问题描述】:

我有一个用户资源,它被许多其他资源引用。
所以我想创建一个 UserResourceInput :

import React from 'react';
import {ReferenceInput, SelectInput} from 'admin-on-rest';


const UserReferenceInput = (props) => (
    <ReferenceInput reference="user" {...props}>
        <SelectInput optionText="name"/>
    </ReferenceInput>
);
UserReferenceInput.defaultProps = {
    source: 'userId',
    addLabel: true,
    label: 'User'
};

export default UserReferenceInput;

并以这样的简单形式使用它:

ProductCreate = (props) => (
    <Create {...props}>
        <SimpleForm>
            <TextInput source="title" />
            <NumberInput source="price" />
            <UserReferenceInput />
        </SimpleForm>
    </Create>
);

但我收到此错误:

【问题讨论】:

  • 如何从输入中得到props

标签: javascript reactjs redux redux-form admin-on-rest


【解决方案1】:

您缺少 ReferenceInput 上的 source 属性。因此,它无法找到它的价值。您可以直接在 UserReferenceInput 中定义它,也可以将其作为 prop 传递给表单中的 UserReferenceInput

编辑

不要在ReferenceInput 上使用addLabel 属性,它不支持。而是将其应用于 SelectInput 子级。

【讨论】:

  • 源码在defaultProps中。
  • 谢谢,但它也需要addField:true 才能工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-27
  • 1970-01-01
  • 2018-08-04
  • 2017-09-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多