I have defined the object, and array in 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
}
Then, for each DHTMLX Grid row, it includes 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 rows filled in the Grid, it will have an array, with two objects, each with the parameters listed above, but the two get the same values, the values of the last line swept by the code, that is, two equal objects, when the lines are different. Debugging, I saw that by adding the object to the array with itensList.push(oItem);
, it makes the object that already be there have the same values.
How to make each object have the values of each line?