Actionscript 3 从mx:Repeater内部获取mx:CheckBox值
我有一个对象数组,用作中继器的数据源Actionscript 3 从mx:Repeater内部获取mx:CheckBox值,actionscript-3,flex3,mxml,Actionscript 3,Flex3,Mxml,我有一个对象数组,用作中继器的数据源 <mx:Repeater id="categoryRepeater" dataProvider="{this.allCategories}"> <mx:HBox> <mx:Spacer width="20"/> <mx:CheckBox id="categoryCheckBox" label="{categoryRepeater.currentItem.question}"/> </mx:HBox>
<mx:Repeater id="categoryRepeater" dataProvider="{this.allCategories}">
<mx:HBox>
<mx:Spacer width="20"/>
<mx:CheckBox id="categoryCheckBox" label="{categoryRepeater.currentItem.question}"/>
</mx:HBox>
</mx:Repeater>
我想知道列表中的哪些复选框已被选中,但我不确定如何做。我知道我可以在单击某个函数时添加它,但我不知道如何判断哪个复选框调用了该函数。使用该属性。我意识到这是一篇非常古老的文章,但我遇到了同样的问题,currentIndex对我来说不是一个足够的答案。我发现更好的方法是在单击时创建一个函数:
<mx:Repeater id="rp" dataProvider="{dp}">
<s:CheckBox height="100%" width="100%" label="{String(rp.currentItem)}"
click="showAlert(event);"/>
</mx:Repeater>
通过这种方式,您可以将事件作为ActionScript代码中的复选框来处理,并查找值,例如是否已选择该事件等。您能为我指出示例的方向吗?以下是我正在尝试的:但是,似乎从未调用过该函数,也就是说categoryRepeater.currentIndex我最初发布的Flex 3文档的链接底部有一个示例。只需将currentTarget.getRepeaterItem()替换为currentTarget.currentIndex,然后重试。
private function showAlert(evt:MouseEvent):void {
var curBox:CheckBox = evt.currentTarget as CheckBox;
var str:String = curBox.content.toString();
if(curBox.selected)
Alert.show(str + " clicked");
}