在flex移动列表上工作。 list使用itemrenderer表示。 这是itemrendeerer ..
<s:Image id="img" x="30" y="50"/>
<s:Label id="nameLbl" width="100%" height="100%" text="Label" textAlign="center" verticalAlign="middle"/>
<s:Button id="checkMarkLabel" label="+" height="100%" />
on selected ::
protected function onClicked(event:MouseEvent):void
{
if(checkMarkLabel.label =="✓")
{
checkMarkLabel.label = "+";
}
else if(checkMarkLabel.label == "+" )
{
checkMarkLabel.label = "✓";
trace("id::"+event.currentTarget.data.id)
//FlexGlobals.topLevelApplication.selectedId = event.currentTarget.data.id;
}
}
图像为您提供清晰的图像。 在列表中选择一些项目之后,如果我滚动列表,则检查项目将被取消选中并且未检查的项目会被检查。任何答案都是可以理解的..
答案 0 :(得分:0)
Flex不会为列表中的每个项目创建渲染器,而是Flex创建一些渲染器(在您的情况下为6)并且重用它们。
你必须保存关于点击列表项的数据(可能使用一些单例),然后你必须覆盖渲染器类中的set data方法(在这个方法中你得到渲染器的列表项),然后你弄清楚是否单击了这个项目并设置为checkMarkLabel对应的符号。
答案 1 :(得分:0)
在列表中,您可以将属性“useVirtualLayout”设置为false。这将为列表中的每个项生成唯一的itemrenderer。这也是安东所说的。 然而,这对资源不太友好。如果你的列表真的很大,它会占用更多的内存。
您应该使用列表与itemrenderers结合使用的状态。
示例itemrenderer:
<fx:Script>
<![CDATA[
protected function marker_clickHandler(event:MouseEvent):void {
marker.label = marker.label == "V" ? "+" : "V";
}
]]>
</fx:Script>
<s:states>
<s:State name="normal"/>
<s:State name="selected"/>
</s:states>
<s:Button label.selected="V" label.normal="+"/>
<s:Button y="10" id="marker" click="marker_clickHandler(event)" label="+"/>
如果您将此作为itemrenderer使用,则使用状态的按钮将按预期更新,但正如Anton所述,手动onClick标记的按钮将不会按预期更新。
答案 2 :(得分:0)
这个答案建立在Robin van den Bogaard的回答之上。
假设您当前的dataProvider
包含如下所示的对象:
public class MyData {
[Bindable]
private var imgUrl:String;
[Bindable]
private var name:String;
}
为其添加新字段:
[Bindable]
private var chosen:Boolean;
(如果您没有[Bindable]
,请添加它以启用数据项上的数据绑定。)
然后您的itemRenderer
可能如下所示,滚动时会自动更新:
<fx:Script>
<![CDATA[
protected function marker_clickHandler(event:MouseEvent):void {
data.chosen = !data.chosen;
}
]]>
</fx:Script>
<s:states>
<s:State name="normal"/>
<s:State name="selected"/>
</s:states>
<s:Image id="img" x="30" y="50" source="{data.imgUrl}" />
<s:Label id="nameLbl" width="100%" height="100%" text="Label" textAlign="center" verticalAlign="middle" text="{data.name}" />
<s:Button id="checkMarkLabel" label="{data.chosen ? '✓' : '+'}" height="100%" click="marker_clickHandler(event)" />