Actionscript 3 如何将对象动态添加到Flex 3阵列集合?
我已经彻底搜索过了,但没有找到这个问题的答案。也许我的问题错了。我的tabNavigator的每个画布上总共有30个孩子。该代码可以很好地对子项进行计数和迭代,但是当我尝试向ArrayCollection添加一个项时,它就会崩溃。代码如下:Actionscript 3 如何将对象动态添加到Flex 3阵列集合?,actionscript-3,apache-flex,actionscript,flex3,arraycollection,Actionscript 3,Apache Flex,Actionscript,Flex3,Arraycollection,我已经彻底搜索过了,但没有找到这个问题的答案。也许我的问题错了。我的tabNavigator的每个画布上总共有30个孩子。该代码可以很好地对子项进行计数和迭代,但是当我尝试向ArrayCollection添加一个项时,它就会崩溃。代码如下: private function addrNewDB():void { var q:int = 0; var t:int = tabNavigator.numChildren; while (q<t){
private function addrNewDB():void {
var q:int = 0;
var t:int = tabNavigator.numChildren;
while (q<t){
var TNG:Array = tabNavigator.getChildren();
var qnn:Array = TNG[q].getChildren() as Array;
var gat:int = 0;
var pat:int = TNG[q].numChildren;
var newItem:Object = new Object();
while (gat<pat){
if (UIComponent(qunn[gat]) is CheckBox){
if (qunn[gat].selected == true){
var game:String = "Y";
}
else {
gm = "N";
}
Alert.show("gat: "+String(gat)+" | pat: "+String(pat)+"\n"+qnn[gat].id+" - "+qnn[gat].label+": "+gm);
}
gat++;
}
q++;
}
}
这是:
newItem['merch'] = lblMerchID.text;
newItem['item'] = qnn(gat).label;
newItem['qual' = "";
newItem['loc'] = "";
newItem['id'] = qnn(gat).id;
HardwareItems.addItem(newItem);
HardwareItems.refresh();
这也是:
newItem.merch = lblMerchID.text;
newItem.item = qnn(gat).label;
newItem.qual = "";
newItem.loc = "";
newItem.id = qnn(gat).id;
HardwareItems.addItem(newItem);
HardwareItems.refresh();
很明显,这些都是不正确的方式来实现我想要的,但我只是在尝试任何事情。顺便说一句,这些编码暴行都没有引发任何错误。但当我试过的时候,我得到了一个警告。。。第一个复选框位于30项中的23项
我已经阅读了所有关于ArrayCollection和数组语法的文档,我想我还是不明白。感谢您的帮助。多谢各位 addItem()方法无论如何都应该有效
请确保您:
var HardwareItems:ArrayCollection = new ArrayCollection();
var newItem:Object = {};
newItem['merch'] = lblMerchID.text;
newItem['item'] = qnn(gat).label;
newItem['qual' = "";
newItem['loc'] = "";
newItem['id'] = qnn(gat).id;
HardwareItems.source.push(newItem);
HardwareItems.refresh();
你有定义硬件项目的代码吗?根据您的描述,这听起来像是
var HardwareItems:ArrayCollection
,因此我将忽略第一个明显的可能问题,即HardwareItems是一个类而不是一个实例。我能想到的另一件事是,如果您将HardwareItems用于数据绑定,请确保它是[Bindable],否则,更改不会传播到用户。在调试模式下,添加项后,arrayCollection是否具有该项?这将是第一件要做的事check@ketan请停止批量编辑标签,因为它会将旧问题推到队列顶部。你也在
var HardwareItems:ArrayCollection = new ArrayCollection();
var newItem:Object = {};
newItem['merch'] = lblMerchID.text;
newItem['item'] = qnn(gat).label;
newItem['qual' = "";
newItem['loc'] = "";
newItem['id'] = qnn(gat).id;
HardwareItems.source.push(newItem);
HardwareItems.refresh();