在数组Angular 2中动态添加值

费尔南多·赫里克·鲁宾·皮奥利

如何动态地在数组中添加值,我试过这样的:

this.socios.forEach((data) => {
            this.fieldsSocios = [ 
        new ArraySocios(data.nome, data.participacao)

  ];

但是,在 fieldsSocios 中只有最后添加的值。实际上应该是fieldSocios里面的3个对象。

尤尼斯

您在每次迭代中都在初始化数组,this.fieldsSocios应该在循环开始之前进行初始化。

this.fieldsSocios = [];
this.socios.forEach((data) => {
 this.fieldsSocios.push(new ArraySocios(data.nome, data.participacao));
});

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章