当在数组中更改字段时,休息字段会消失,如何呈现它?

时间:2017-02-27 05:53:13

标签: reactjs redux redux-form

我有FieldArray并且每个项目生成:

export const Options = (props) => {   return <div>{
    props.fields.map((op, index) =>
        <Fields
          key={index}
          names={[
            `${props.fields.name}[${index}].${op.fieldName}`,
            `${props.fields.name}[${index}].optionSubList`,
            `${props.fields.name}[${index}].otherValue`
          ]}
          component={SelectList}
          otherValue={op.otherValue}
          fieldName={op.fieldName}
          important={op.required}
          className={op.classNames}
          label={op.label}
          list={op.options}
        />
    )   }</div>; };

更改其中一个字段后,其他字段消失。

我尝试添加 initialValue :这不起作用,如果我还剩下一个剩余字段,则完全相同

我还设置了一个标志 enableReinitialize 相同的

1 个答案:

答案 0 :(得分:1)

我对[${index}]包含有点担心,因为props.fields.name的结尾应该已经有[42]类型索引。我不知道相邻组件的所有细节,但我建议删除索引。

<Fields
  key={index}
  names={[
    `${props.fields.name}.${op.fieldName}`,
    `${props.fields.name}.optionSubList`,
    `${props.fields.name}.otherValue`
  ]}
  .../>