Typescript 在它之后打开表单';他被推了

Typescript 在它之后打开表单';他被推了,typescript,Typescript,在我推送一个新表单后,如果它是一个折叠的手风琴列表,我将如何打开该表单 /** 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 = fa

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

  /** 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还是很陌生,所以我很抱歉。

您希望在
切换节
函数中使用索引,所以在添加pass调用
切换节
函数后,从
第一个addfield
函数使用最后插入的表单索引,如下所示

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