我需要为列表中的每个项添加一个按钮。这是我的ItemRenderer的代码:
<?xml version="1.0" encoding="utf-8"?>
<!--
Item Renderer to render product preview images as thumbnails
-->
<s:ItemRenderer
width="200"
clipAndEnableScrolling="false"
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
autoDrawBackground="true"
xmlns:model="com.pms.approvaltool.model.*"
xmlns:components="com.pms.approvaltool.components.*"
xmlns:spinner="de.profundus.editor.components.spinner.*">
<fx:Script>
<![CDATA[
protected function button1_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
}
]]>
</fx:Script>
<s:VGroup
width="100%"
paddingTop="10"
paddingBottom="10"
paddingLeft="10"
paddingRight="10"
verticalAlign="middle"
gap="3">
<s:Label width="100%"
text="{(data as Page).label}"/>
<!-- preview item thumbnail -->
<mx:Image
maxWidth="200" maxHeight="150"
source="{(data as Page).previewUrl}"
scaleContent="true"
maintainAspectRatio="true"/>
<s:Button click="button1_clickHandler(event)"/>
</s:VGroup>
</s:ItemRenderer>
问题是,当我点击按钮时,相关项目将被选中。我怎么能避免这个?
答案 0 :(得分:3)
尝试停止将mouseDown事件传播到datagrid,如果它将像...一样工作
<s:Button mouseDown="event.stopPropagation()" />
答案 1 :(得分:1)
根据http://forums.adobe.com/thread/776750,您可以使用event.stopImmediatePropagation
:
<s:Button mouseDown="event.stopImmediatePropagation()" />
以下SO帖子也可能有所帮助: Prevent selection of a particular item in spark list
答案 2 :(得分:0)
您可以从button1_clickHandler访问List并将list的selectionIndex设置为-1。如果itemRenderer是内联的,您可以尝试使用parentDocument访问父列表。