开发者

Object to arraycollection

开发者 https://www.devze.com 2023-03-06 07:41 出处:网络
linedataColl is an AC that contains 100+ of rows extract from CSV, I wish to add item into SuperDataCollection object by object but the only problem was I\'m unable to开发者_JS百科 see any data displa

linedataColl is an AC that contains 100+ of rows extract from CSV, I wish to add item into SuperDataCollection object by object but the only problem was I'm unable to开发者_JS百科 see any data display in "S" which is a datagrid. What wrong with my code?

   var superDataCollection:ArrayCollection = new ArrayCollection();
   var dc:ArrayCollection = new ArrayCollection();
   var di:Object = new Object();
   for(var aa:int=0; aa<5;aa++){
    di.username = linedataColl[aa].username;
    di.email = linedataColl[aa].email;
    dc.addItem(di);
    superDataCollection.addItem(dc);
}
s.dataProvider = dc;

For my datagrid:

var columns:Array = [];
var myDataGridColumn:DataGridColumn = new DataGridColumn("id");
myDataGridColumn.headerText = "ID";
myDataGridColumn.width = 40;
columns.push(myDataGridColumn);
... // so on for other column
dg1.columns = columns;      


I Found Two thing wrong in your code

1) Declare di in For loop, new instance for each iteration

for(var aa:int=0; aa<5;aa++){
     var di:Object = new Object();  

2) You are not defining proper dataField for DataGridColumn, although you are passing id in constructor, but i didn't find it in upper code you share,it could be

di.id = aa

or

myDataGridColumn.headerText = "ID";   
myDataGridColumn.width = 40;   
myDataGridColumn.dataField = "username"; 

Hopes that helps

0

精彩评论

暂无评论...
验证码 换一张
取 消