4
I have defined the object, and the array in the scope.
//Define o array que deve ser preenchido com os objetos
var itensList = [];
//Define os argumentos do objeto
var oItem = {
Codig: 0,
Desc: "",
Unid: "KG",
Quant: 0,
Custo: 0,
IL: "",
Centro: "",
Saldo: o
}
So for each row of the DHTMLX Grid, include the results in the object...
//Para cada linha do grid, busca os resultados
mygrid.forEachRow(function (id) {
//Se o Codigo do item for maior que zero..
if (mygrid.cells(id, 0).getValue() != 0) {
// .. adiciona os valores ao objeto
oItem.Codig = mygrid.cells(id, 0).getValue();
oItem.Desc = mygrid.cells(id, 1).getValue();
oItem.Unid = mygrid.cells(id, 2).getValue();
oItem.Quant = mygrid.cells(id, 3).getValue();
oItem.Custo = mygrid.cells(id, 4).getValue();
oItem.IL = mygrid.cells(id, 5).getValue();
oItem.Centro = mygrid.cells(id, 6).getValue();
oItem.Saldo = mygrid.cells(id, 7).getValue();
// Adiciona o objeto a lista
itensList.push(oItem);
}
});
At the end of this program, if I have two lines filled in the Grid, it will have an array, with two objects, each with the parameters listed above, but, the two stay with the same values, the values of the last line swept by the code, ie two objects equal, when the lines are different. Debugging, I saw that when adding the object to the array with itensList.push(oItem);
, it makes the object that is already there have the same values.
How to make each object have the values of each line?
One remark: in fact the
var
can stay out of theif
, at the top of the function. There is no "scope ofif
" in js.– bfavaretto
@bfavaretto Indeed. I meant "inside" the if.
– Beterraba