首页 > 解决方案 > 推送后打开表单

问题描述

在我推送一个新表单后,如果它是折叠的手风琴列表,我将如何打开该表单?

  /** Collapse and expand fields. */
  toggleSection(index) {
      this.fields[index].open = !this.fields[index].open;
  }

  /** Adds the first new field in the form. */
  firstAddField() {
    this.nextPage = false;
    var newForm = this.fields.push(this.form);
    // this.toggleSection(newForm);
  }

当前发生的情况是,当我单击“添加另一个字段”按钮时,firstAddField()会调用该方法,但是一旦完成,它就会添加折叠的新表单(下图)。我可以单击该项目,然后通过该toggleSection()方法扩展它,但我希望在我推送一个新项目后运行它。

新字段是添加的新折叠表单

我对 Typescript 还是很陌生,所以我很抱歉。

标签: typescript

解决方案


您期望toggleSection函数中有索引,因此firstAddField在添加传递调用toggleSection函数和最后插入的表单索引之后的函数,如下所示。

firstAddField() {
    this.nextPage = false;
    var newForm = this.fields.push(this.form);
    this.toggleSection(this.fields.length - 1);
  }

推荐阅读