我如何编写一个构建此数组的过程,以便我可以选择尽可能多的参数名称,例如KBP?我想了?
public var expenses:ArrayCollection = new ArrayCollection([
{Impact:"A", KBP1:1, KBP2:0, KBP3:0, KBP4:0 },
{Impact:"B", KBP1:0, KBP2:0, KBP3:0, KBP4:0 },
{Impact:"C", KBP1:0, KBP2:2, KBP3:3, KBP4:0 },
{Impact:"D", KBP1:0, KBP2:0, KBP3:0, KBP4:8 },
{Impact:"E", KBP1:0, KBP2:0, KBP3:0, KBP4:0 }
]);
答案 0 :(得分:2)
如下所示:
var arrayLength:int = 100;
var kbpsLength:int = 50;
var expensesArray:Array = [];
for (var i:int = 0; i < arrayLength; i ++)
{
var item:Object = {Impact:"A"};
for (var j:int = 0; j < kbpsLength; j ++)
{
item["KBP" + (j + 1)] = 0;
}
expensesArray.push(item);
}
var expenses:ArrayCollection = new ArrayCollection(expensesArray);
答案 1 :(得分:1)
这是我对你的问题的理解。如果这不是您想要的,请随时澄清。
var expenses:ArrayCollection = new ArrayCollection();
(loop conditions?)
{
var item:Object = {};
item.Impact = "A";
item.KBP1 = 0;
item.KBP2 = 0;
item.KBP3 = 0;
item.KBP4 = 0;
item.KBP5 = 0;
...
expenses.addItem(item)
}