1

我的组件中有这个表单:

this.state.customFieldsArray.length > 0 &&
          (
            <Form
              ref="customForm"
              type={this.customForm}
              options={this.customFormOptions}
            />
          )}

当我单击按钮时,我想向表单添加更多选项(以便呈现更多字段)。这是处理单击按钮的方法:

  addCustomField = () => {
 let newFieldName = this.state.customFieldLabel;
 let newField = { newFieldName: "" };
 this.customFormOptions.fields[newFieldName] = {
  label: newFieldName
 };
  tempCustomFieldsArray.push(newField);
  this.setState({
   customFieldsArray: tempCustomFieldsArray
 });
 };

我已经尝试过了,但它没有用。

4

1 回答 1

0

这段代码对我有用,创建调用函数的结构表单模型,并在那里使用你的条件

formModel: t.struct({
  customFields: this.getCustomFields(),
}),

然后您创建 customFields 函数,例如,

  getCustomFields = () => {
    const customFields = {}
    //write your condition here
    return t.enums(customFields)
  }

于 2019-12-07T17:04:08.907 回答