The reason why a new row cannot be added when there is no data is because the initial value of the `list` field in the form is not set properly. \n\nTo fix this issue, you can modify the `renderContent` method in the `UpdateForm` component as follows:\n\njavascript\nrenderContent = formVals => {\n const { filterSelect } = this.state;\n const {\n form: { getFieldDecorator },\n filterList,\n } = this.props;\n\n const list = formVals?.typeList || [{ type: [], name: '' }]; // Set initial value of \`list\` field\n getFieldDecorator('list', { initialValue: list });\n\n // Rest of the code...\n}\n\n\nBy setting the initial value of `list` to an array with an empty object, the form will render an empty row when there is no data. The `add` function can then be used to add a new row as expected.

React Antd Form - Adding New Rows with Initial Values

原文地址: https://www.cveoy.top/t/topic/qk8G 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录