What exactly am I doing wrong here? Trying to fill and ArrayCollection with an Object
public function capturaPermisos():ArrayCollection{
var arrayColl:ArrayCollection = new ArrayCollection();
for(var i:int=0; i < dataProvider.length; i++){
object.idModulo = dataProvider[i].idModulo;
object.consultar = dataProvider[i].consultar;
object.agregar = dataProvider[i].agregar;
object.modificar = dataProvider[i].modificar;
object.eliminar = dataProvider[i].eliminar;
arrayColl[i].addItem(object);
}
return arrayColl;
}
dataProvider comes from a datagrid, hence the cycle. The object is declared globally outside the funcion.
for each(var per:Object in adgPermisos.dataProvider)
{
permiso.idModulo = per.idModulo;
permiso.consultar = per.consultar;
permiso.agregar = per.agregar;
permiso.modificar = per.modificar;
permiso.eliminar = per.eliminar;
permisos.addItem(permiso);
}
The second loop does exactly the same wrong result.
It saves the last registry of my dataprovider in all 3 lines of the arraycollection (the dataprovider.length is 3)
My dataProvider is an arrayCollection too, but it is not the same Arrcooll that fills my Datagrid. When I want to send my data to server there are d开发者_开发技巧iferent values added from checkboxes inside my datagrid and renders the arrayCollection different than it was when the datagrid was filled.
I just want to fill another arrayCollection to send it to my java webservice like this;
"It saves the last registry of my dataprovider in all 3 lines of the arraycollection": you are probably referencing the same object [permiso] in the loop 3 times. As a result you add this same object 3 times, and you change this same object again 3 times. (As a result, all 3 entries in your permisos contain the same object permiso which has been changed 3 times). Try the following code to solve the issue:
for each(var per:Object in adgPermisos.dataProvider)
{
var newItem : Object = ObjectUtil.clone(permiso);
newItem.idModulo = per.idModulo;
newItem.consultar = per.consultar;
newItem.agregar = per.agregar;
newItem.modificar = per.modificar;
newItem.eliminar = per.eliminar;
permisos.addItem(newItem);
}
精彩评论