Adobe Flex 4.5 Spark:将 ItemRenderer 组件绑定到父级
在Flex 3中,过去可以通过outerDocument在itemRenderer中绑定组件属性。例如,如果 itemRenderer 中有一个图像仅在父级的给定条件下显示,则类似这样的内容将完美工作:
<mx:itemRenderer>
<mx:Component>
<mx:Label text="{data}"/>
<mx:Image id="img" visible="{outerDocument.ShowImage}" includeInLayout="{outerDocument.ShowImage}"/>
</mx:Component>
</mx:itemRenderer>
外部文档(不是列表,而是列表所在的 mxml)包含某些内容就像
[Bindable]
public function get ShowImage():void
{
return showImage;
}
public function set ShowImage(val:Boolean):void
{
showImage = val;
}
我尝试在 Flex 4.5 中使用 Spark 项目渲染器使用parentDocument 做同样的事情,但它似乎不知道绑定。当我在 Flex 4.5 中执行此操作时,itemRenderer 似乎不知道parentDocument ShowImage 何时发生更改。
有谁见过这个问题并能够提供解决方案吗?
编辑:添加 Spark 源 按照此处的要求,我的 Spark 源是:
MyItemRenderer.mxml
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<s:Label id="myLabel" text="{data}/>
<s:Image src="something.png" visible="{parentDocument.ShowImage}" includeInLayout="{parentDocument.ShowImage}"/>
</s:ItemRenderer>
RendererContainer.mxml
<s:Panel xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
private var showImage:Boolean = false;
[Bindable]
public function set ShowImage(val:Boolean):void
{
showImage = val;
}
public function get ShowImage():Boolean
{
return showImage;
}
]]>
</fx:Script>
<!-- Content Group -->
<s:List id="lstCell" width="100%" height="100%" itemRenderer="MyItemRenderer">
</s:List>
</s:Panel>
好的,RendererContainer.mxml 外部的包装器中有一个复选框,用于调度通过更改 Bindable 布尔值来处理的自定义事件。该 var 中的更改随后会更改 RendererContainer 组件上的 ShowImage 属性。我希望 MyItemRenderer 能够拾取绑定,但它似乎不起作用。
所以我的外包装将像这样访问 ShowImage
<comp:RendererContainer id="myId" ShowImage="{myCheckbox.selected}"/>
In Flex 3, it used to be possible to bind a component property within an itemRenderer via outerDocument. So for instance, if there was a image inside an itemRenderer that was only displayed on a given condition of the parent, something like this would work perfectly:
<mx:itemRenderer>
<mx:Component>
<mx:Label text="{data}"/>
<mx:Image id="img" visible="{outerDocument.ShowImage}" includeInLayout="{outerDocument.ShowImage}"/>
</mx:Component>
</mx:itemRenderer>
where the outer document (not the list, but the mxml the list is in) contained something like
[Bindable]
public function get ShowImage():void
{
return showImage;
}
public function set ShowImage(val:Boolean):void
{
showImage = val;
}
I've tried to do the same thing in Flex 4.5 using Spark item renderers using parentDocument, but it doesn't seem to be aware to the binding. When I do this in Flex 4.5, the itemRenderer doesn't seem to be aware when the parentDocument ShowImage changes.
Has anyone seen this issue and is able to offer a solution?
EDIT: Add Spark Source
As requested here is my spark source:
MyItemRenderer.mxml
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<s:Label id="myLabel" text="{data}/>
<s:Image src="something.png" visible="{parentDocument.ShowImage}" includeInLayout="{parentDocument.ShowImage}"/>
</s:ItemRenderer>
RendererContainer.mxml
<s:Panel xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
private var showImage:Boolean = false;
[Bindable]
public function set ShowImage(val:Boolean):void
{
showImage = val;
}
public function get ShowImage():Boolean
{
return showImage;
}
]]>
</fx:Script>
<!-- Content Group -->
<s:List id="lstCell" width="100%" height="100%" itemRenderer="MyItemRenderer">
</s:List>
</s:Panel>
Ok so there is a checkbox in a wrapper outside of RendererContainer.mxml that dispatches a custom event that is handled by changing a Bindable Boolean. The change in that var then changes the ShowImage property on my RendererContainer component. I would expect that the binding would then be picked up by MyItemRenderer but it doesnt seem to be working.
So my outer wrapper would access ShowImage like this
<comp:RendererContainer id="myId" ShowImage="{myCheckbox.selected}"/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为这应该对你有用,
YourTypeHere
将是包含的类对象,请确保 ShowImage 属性是公共且可绑定的。
PS 请不要以大写字母开头的属性命名,包括吸气剂,请考虑将其命名为
showImage
并将您的私有变量命名为_showImage
之类的名称:DI think this should do the trick for you,
YourTypeHere
would be the class of the containingobject, make sure the
ShowImage
property is public and bindable.P.s. please don't name properties with a starting uppercase letter, including getters, consider naming it
showImage
and your private var to something like_showImage
instead :D您的 getter 似乎返回类型为 void。将其更改为布尔值
Your getter seems to have return type as void. Change that to Boolean
这会有帮助。
This will help.
以下工作完全正常:
Following works perfectly fine: