我在redux-form
中使用FieldArray,但与此同时,当我要编辑表单TypeError: (value || []).map is not a function
时,它给我错误。有人可以帮我解决这个问题。我是Redux表单的新手,请帮助我,我真的需要尽快解决此问题。我将附加我的代码,请检查它,当我要编辑表单时会发生此错误。
预先感谢
代码
renderMembers = ({
fields,
meta: { error, submitFailed },
fieldType,
fieldDisabled,
}) => (
<div>
{fields.map((item, index) => (
<div key={index} className="row mt-2 mb-3">
<div className="col-sm-3">
<Field
name={`${item}.fieldName`}
type="text"
component={renderField}
label="Label Name"
/>
</div>
<div className="col-sm-2">
<Field
name={`${item}.fieldType`}
onChange={(value) => {
const newItems = [...this.state.fieldType];
newItems[index] = value.value;
this.setState((prevState) => ({
fieldType: newItems,
fieldDisabled: false,
fieldIndex: {
...this.state.fieldIndex,
fieldIndex: item,
},
}));
}}
type="text"
component={customFieldChooice}
label="Last Name"
/>
</div>
{fieldType[index] === "text" &&
`optional_fields[${index}]` === item ? (
<div className="col-sm-5">
<Field
name={`${item}.value`}
type="text"
component={renderField}
label="Label Name"
customValue={true}
/>
</div>
) : fieldType[index] === "dropdown" &&
`optional_fields[${index}]` === item ? (
<div className="col-sm-5">
<Field
name={`${item}.value`}
type="text"
component={customDropdown}
label="Label Name"
/>
</div>
) : (
<div className="col-sm-5">
<Field
name={`${item}.disableValue`}
type="text"
component={renderField}
customValue={fieldDisabled}
label="Label Name"
/>
</div>
)}
<button
className="removeButton"
type="button"
title="Remove Field"
onClick={() => {
fields.remove(index);
const list = this.state.fieldType;
list.splice(index, 1);
this.setState({
fieldType: list,
});
}}
/>
</div>
))}
<div className="row">
<div className="col-sm-2">
<button
type="button"
onClick={() => {
fields.length <= 9 && fields.push({});
this.setState({
fieldDisabled: true,
});
}}
className="addMoreButton"
>
Add Custom Field
</button>
{submitFailed && error && <span>{error}</span>}
</div>
</div>
</div>
);