P粉9405389472023-08-23 14:57:55
You can also use hooks
import { Form } from "antd" const [form] = Form.useForm(); fetch('api') .then(results=>{ return results.json() }) .then(data=>{ form.setFieldsValue({ sample: data.dataYouWant }); <Form form = {form}> <Form.Item name = "sample"> <Input /> </Form.Item> </Form>
P粉0789451822023-08-23 12:33:30
The documentation states:
When data is loaded from the backend, just call setFieldsValue
:
fetch('http://localhost:5728/Fields/get/' + this.state.Data.Id) .then(results=>{ return results.json() }) .then(data=>{ this.props.form.setFieldsValue({ Id: data.field.Id, Name: data.field.Name, Description: data.field.Description, Value: data.field.Value }) })
Or more succinctly, if the backend's data.field
exactly matches the field name:
this.props.form.setFieldsValue(data.field)