开发者

Dynamically adding rows AdvancedDataGrid Flex

I have an AdvancedDataGrid being built dynamically from an html table. The html is provided by a server so my code has to work dynamically for different columns/rows.

I have the columns being built and they display properly, however when I get to adding the rows is where i have issues. the follow code snippet shows iterating over all of the columns and adding a value under each of those columns to an object (to make a complete row) and then adding that to the ArrayCollection that later gets set to the dataProvider for the AdvancedDataGrid

//create an item to work with
var chartItem:Object = new Object();
for( var j:int = 0; j < columnResult.length ; j++ ) 
{
    //this is the data that goes under the column (headerArray)
    var item:String = removeformat(removetd(columnResult[j]));
    //grab the header (this is which column the value will be added
    开发者_如何学运维var head:String = headerArray[j];
    //set the value to header (pair)
    chartItem[head] = item;
}
//add the chartItem (row) to the main collection
arr.addItem(chartItem);

my issue is that when "head" has a value of 0, as in the column title is '0', the item is added at position [0] instead of at 0 as a string.

I looked up some examples and tried with:

chartItem.head but that just assumes the column title is 'head' instead of grabbing the value of the head var


It is not possible to use numbers as an index in associative arrays.

Most of the time the index in an associative array is just a variable name of an Object. That's why you can access the data either with obj["someKey"] or obj.someKey. Of course you can use characters within your keys that are not allowed within variable names (like spaces, special symbols). However, you can access those only with brackets, not with dot (obj["foo/bar"] works, obj.foo/bar won't work). So, this is not recommended...

Well, back to your problem: I'd suggest you prefix all your column names with a character (e.g. use "_0"). Since you create the AdvancedDataGrid columns dynamically that shouldn't be a problem. You can explicityl set the headerText of those columns in order to still show "0" in the column header instead of "_0".

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜