我有一个对象数组,用作我的中继器的数据源。
<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>我希望能够分辨出列表中的哪些复选框已被选中,但我不确定如何操作。我知道当一个函数被点击时,我可以添加它,但是我不知道如何判断哪个复选框调用了这个函数。
发布于 2009-04-28 17:11:06
使用currentIndex属性。
发布于 2011-02-03 23:43:06
我意识到这是一个非常古老的帖子,但我遇到了同样的问题,currentIndex对我来说并不是一个足够的答案。我发现更有效的方法是在点击时创建一个函数:
<mx:Repeater id="rp" dataProvider="{dp}">
<s:CheckBox height="100%" width="100%" label="{String(rp.currentItem)}"
click="showAlert(event);"/>
</mx:Repeater>showAlert函数看起来像这样:
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");
}通过这种方式,您可以将事件作为ActionScript代码中的CheckBox处理,并查找诸如是否已被选中等值。
https://stackoverflow.com/questions/798900
复制相似问题