Arrays 将数据提供程序分配给Flex';s弹出菜单按钮
我试图让两个不同的测试下拉列表以相同的方式工作Arrays 将数据提供程序分配给Flex';s弹出菜单按钮,arrays,actionscript-3,apache-flex,associative-array,flex-mx,Arrays,Actionscript 3,Apache Flex,Associative Array,Flex Mx,我试图让两个不同的测试下拉列表以相同的方式工作 <mx:HBox x="10" y="50" > <mx:PopUpMenuButton id="associativeDD"/> </mx:HBox> <mx:HBox x="100" y="50" > <mx:PopUpMenuButton id="indexedDD"/> </mx:HBox> 下面是它的外观: 在我使用关联数组分配数据提供程序的开头有
<mx:HBox x="10" y="50" >
<mx:PopUpMenuButton id="associativeDD"/>
</mx:HBox>
<mx:HBox x="100" y="50" >
<mx:PopUpMenuButton id="indexedDD"/>
</mx:HBox>
下面是它的外观:
在我使用关联数组分配数据提供程序的开头有一个空白点,是否有任何方法“正确”执行此操作,使其看起来像索引数组一样正确?Actionscript数组是零基且稀疏的。这意味着,如果您创建一个数组并插入索引为
1
的第一个元素,那么数组的大小将为2
,而索引为0
的元素将为未定义的
因此,为了获得相同的结果,对于关联数组,您需要从索引0
开始
var arr1:Array = new Array();
arr1['1'] = ({label: "test1"});
arr1['2'] = ({label: "test2"});
arr1['3'] = ({label: "test3"});
associativeDD.dataProvider = arr1;
var arr2:Array = new Array();
arr2.push({label: "test1"});
arr2.push({label: "test2"});
arr2.push({label: "test3"});
indexedDD.dataProvider = arr2;