动态添加行AdvancedDataGrid Flex

| 我有一个从html表动态生成的AdvancedDataGrid。该html由服务器提供,因此我的代码必须针对不同的列/行动态工作。 我有正在构建的列,它们可以正确显示,但是当我添加行时却遇到了问题。以下代码段显示了对所有列进行迭代并在每个列下将一个值添加到一个对象(以形成完整的行),然后将其添加到ArrayCollection中,此后被设置为AdvancedDataGrid的dataProvider
//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);
我的问题是,当\“ head \”的值为0时,例如在列标题为\'0 \'时,该项将在位置[0]而不是在0处作为字符串添加。 我查看了一些示例并尝试: chartItem.head,但仅假设列标题为\'head \'而不是获取head var的值     
已邀请:
        在关联数组中不能使用数字作为索引。 大多数时候,关联数组中的索引只是对象的变量名。这就是为什么您可以使用
obj[\"someKey\"]
obj.someKey
访问数据的原因。当然,您可以在键名中使用变量名中不允许使用的字符(例如空格,特殊符号)。但是,您只能使用方括号而不是点来访问它们(
obj[\"foo/bar\"]
有效,
obj.foo/bar
不起作用)。因此,不建议这样做... 好了,回到您的问题:我建议您为所有列名加上一个字符(例如,使用\“ _ 0 \”)。由于您是动态创建AdvancedDataGrid列的,因此这不是问题。您可以显式设置这些列的
headerText
,以便仍在列标题中显示\“ 0 \”而不是\“ _ 0 \”。     

要回复问题请先登录注册