0
我有2個陣列& 2個複選框中繼器:第二個被填充w /項目從第一個選擇。我可以添加項目沒有問題。那麼如果從第一個複選框中繼器中取消選擇項目,我該如何刪除該項目?從陣列中刪除項目
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
creationComplete="updateOlder();"
>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
public var older:ArrayCollection = new ArrayCollection ([]);
[Bindable]
public var newer:ArrayCollection = new ArrayCollection ([]);
private function updateOlder():void{
older.addItem({label:"item1",desc:"desc1"});
older.addItem({label:"item2",desc:"desc2"});
older.addItem({label:"item3",desc:"desc3"});
}
private function updateNewer(evt:MouseEvent):void{
if(evt.target.selected) {
// add item to array
newer.addItem({ label:evt.currentTarget.label, desc:evt.currentTarget.data });
newer.refresh();
}
else {
// remove item from array
newer.removeItemAt(newRepeater.currentIndex.valueOf());
newer.refresh();
}
}
]]>
</fx:Script>
<mx:HBox width="100%" height="100%">
<mx:VBox width="100%" height="100%">
<mx:Repeater id="oldRepeater" dataProvider="{older}">
<mx:CheckBox color="black" fontFamily="Arial" fontSize="14"
label="{oldRepeater.currentItem.label}"
data="{oldRepeater.currentItem.desc}"
click="updateNewer(event);"
/>
</mx:Repeater>
</mx:VBox>
<mx:VBox width="100%" height="100%">
<mx:Repeater id="newRepeater" dataProvider="{newer}">
<mx:CheckBox color="red" fontFamily="Arial" fontSize="14"
label="{newRepeater.currentItem.label}"
data="{newRepeater.currentItem.desc}"
/>
</mx:Repeater>
</mx:VBox>
</mx:HBox>
</mx:Application>