1

我有一个对象数组,用作中继器的数据源。

<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>

我希望能够知道列表中的哪些复选框已被选中,但我不知道该怎么做。我知道我可以在单击时添加一个函数,但我不知道如何判断哪个复选框调用了该函数。

4

2 回答 2

1

使用该currentIndex物业。

于 2009-04-28T17:11:05.540 回答
1

我意识到这是一个非常古老的帖子,但我遇到了同样的问题,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 处理,并查找值,例如它是否已被选中等。

于 2011-02-03T15:43:06.290 回答