根据Array得到索引循环删除ArrayCollection中的数据出现问题。
?
伪代码描述:
下面的代码能正常工作
for(var i:int,i<array.length;i++){
?arrayColleciont.removeItemAt(i);
}
下面的却不能:
for(var i:int=array.length-1,i<0;i--){
?arrayColleciont.removeItemAt(i);
}
?
?
真实代码:
注意:
unAssignedList和
assignedList
是
mx.controls.List?
,它们的
dataprovider
分别是
unassignedDatas
和
assignedDatas
。
?源码
?private?function?addBtn_clickHandler(event:MouseEvent):void{
???????????????var?selectedIndeies:Array?=?this.unAssignedList.selectedIndices;
????????????????var?selectedItems:Array=this.unAssignedList.selectedItems;
??????????????if(selectedItems.length<=0){
????????????????????????Alert.show("请选择
"+this.title,"
选择
");
????????????????????return;
?????????????}
????????????????//按升序排序
????????????????selectedItems.sort();
????????????????//构造数据源?
???????????????for(var?index1:uint=0;index1<selectedItems.length;index1++){
?????????????????assignedDatas.addItem(selectedItems[index1]);
????????????????}
???????????????????//下面的代码可以正常工作
?????????????
selectedIndeies.sort(Array.DESCENDING);
???????????
?????????????for(var?index:int=0;index<selectedIndeies.length;index++){
??????????????????this.unassignedDatas.removeItemAt(selectedIndeies[index]);
??????????????}
?
?????????????????//下面蓝色的循环代码无法删除? unassignedDatas 的数据。
?
???????????????//selectedIndeies.sort();
?
?????????????????
//
??????
for(var?index:int=selectedIndeies.length-1;index<0;index--){
?????????//??this.unassignedDatas.removeItemAt(selectedIndeies[index]);
//????????????????}
?
//??????????????将数据源提供给
List
以更新
View
????????????????this.assignedList.dataProvider=this.assignedDatas;
????????????????this.unAssignedList.dataProvider=this.unassignedDatas;
????????????}
被扣了分,郁闷中。