如何动态地在数组中添加值,我试过这样:
this.socios.forEach((data) => {
this.fieldsSocios = [
new ArraySocios(data.nome, data.participacao)
];
但是,在fieldsSocios中只有最后添加的值。 实际上应该是fieldSocios内的3个对象。
答案 0 :(得分:0)
你是在每次迭代中初始化数组,this.fieldsSocios
应该在循环开始之前初始化。
this.fieldsSocios = [];
this.socios.forEach((data) => {
this.fieldsSocios.push(new ArraySocios(data.nome, data.participacao));
});