I’m creating an extension of the DataProvider class that receives XML and converts it to a DataProvider automatically. This will simplify sorting XML and binding it to acceptable objects, like a DataGrid.
Where I’m stuck is creating a dynamic array with index names matching the node names. Here’s what I have:
//get the column names
for(var i=0;i<xml[0].children()[0].children().length();i++){
xmlColumns.push(xml[0].children()[0].children()*.name());
}
//populate the dataprovider
for(i=0; i < xml[0].children().length(); i++){
var currentNode = xml[0].children()*;
var currentArray = new Array();
for(var m=0; m < xmlColumns.length; m++){
var nodeName:String = currentNode.children()[m].name();
currentArray.push({nodeName:currentNode.children()[m]});
}
trace(currentArray);
this.addItem(currentArray);
}
Notice the nodeName variable I am trying to use as the alias for the columns. I’ve tried this several ways:
currentArray.push({nodeName:currentNode.children()[m]});
currentArray.push({this[nodeName]:currentNode.children()[m]});
currentArray.push({String(nodeName):currentNode.children()[m]});
currentArray.push({nodeName.toString():currentNode.children()[m]});
currentArray.push({$nodeName:currentNode.children()[m]});
currentArray.push({%nodeName%:currentNode.children()[m]});
currentArray[m][nodeName]=currentNode.children()[m];
I think I’m going to kick myself when I found out what to do here, but quite a few google searches have not yielded much either…
I really appreciate any help.
Thanks,
Stephen