Flex 中的一个关于Repeater组件的问题

	<mx:Tile direction="horizontal" borderStyle="inset">
		<mx:Repeater dataProvider="{imageList}" id="rp">
			<mx:Image source="{rp.currentItem.thumb}" click="{Alert.show(rp.currentItem.thumb)}"/>
		</mx:Repeater>
	</mx:Tile>

 

在做这个测试的例子的时候,发现会产生错误 ,后来仔细想想还是想明白了,在做click事件时,Repeater已经循环结束了, 这时候再去访问rp.currentItem则会产生问题。

 

那么把测试例子改成下面这样

<mx:script>
	function handle(event:MouseEvent){
		Alert.show(event.currentTarget.getRepeaterItem())
	}
</mx:script>

	<mx:Tile direction="horizontal" borderStyle="inset">
		<mx:Repeater dataProvider="{imageList}" id="rp">
			<mx:Image source="{rp.currentItem.thumb}" click="handle(event)"/>
		</mx:Repeater>
	</mx:Tile>

 那么关于event.currentTarget.getRepeaterItem()这个又是怎么回事呢,

event.currentTarget这个不用多讲了,这个例子是Image,那么getRepeaterItem()又不是Image的方法。GOOGLE一下,发现了以下说明

 

 

Repeated components and repeated Repeater components have a getRepeaterItem() method that returns the item in the dataProvider property that was used to produce the object. When the Repeater component finishes repeating, you can use the getRepeaterItem() method to determine what the event handler should do based on the currentItem property. To do so, you pass the event.currentTarget.getRepeaterItem() method to the event handler. The getRepeaterItem() method takes an optional index that specifies which Repeater components you want when nested Repeater components are present; the 0 index is the outermost Repeater component. If you do not specify the index argument, the innermost Repeater component is implied.

 

 那么可以看出,被Repeated的控制可以有一个方法,得到当时currentItem所对应的值。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值