从react-admin中的TextInput读取数据

时间:2018-05-18 13:03:32

标签: reactjs react-admin

我有一个TextInput(source =“values”),我想从那里读取一个按钮并用该值更改字符串值

我的示例代码如下;

class DataTypeCreate extends Component {
    state = {
        values: ''
    }

    addClickedHandler = (x) => {
        let value = this.props.values;
        this.setState((prevValue) => {
            return { values: prevValue.values + ", " + this.values}
        });
        console.log(this.state.values);
    }

    render() {
        return(
            <Create {...this.props}>
                <SimpleForm redirect="list"
                    validate={values => {
                        const errors = {};

                        ["id", "type"].forEach(field => {
                            if (!values[field]) {
                                errors[field] = ["Required field"];
                            }
                        });

                        return errors;
                    }}>
                    <TextInput source="id" label="Name" />
                    <SelectInput
                        source="type"
                        choices={[
                            { name: "String", id: "string" },
                            { name: "Enum", id: "enum" },
                            { name: "Decimal", id: "decimal" }
                        ]}
                    />
                    <TextInput source="values" />
                    <Button clicked={this.addClickedHandler} name="Value"></Button>
                    {/* <ReferenceArrayInput reference="values" source="values" label="Values">
                        <SelectArrayInput>
                            <ChipField source="name" />
                        </SelectArrayInput>
                    </ReferenceArrayInput> */}
                </SimpleForm>
            </Create>
        )
    }
}

export default DataTypeCreate;

是否有可能在react-admin中? 你能帮助我吗? 谢谢

0 个答案:

没有答案