apache-flex - Adobe Flex 4.5 Spark : Binding ItemRenderer Component to Parent

标签 apache-flex flex4.5 itemrenderer flex-spark

在Flex 3中,过去可以通过outerDocument在itemRenderer中绑定(bind)组件属性。例如,如果 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 执行相同的操作,但它似乎不知道绑定(bind)。当我在 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 bool 值来处理的自定义事件。该 var 中的更改随后会更改 RendererContainer 组件上的 ShowImage 属性。我希望 MyItemRenderer 能够拾取该绑定(bind),但它似乎不起作用。

所以我的外包装将像这样访问 ShowImage

<comp:RendererContainer id="myId" ShowImage="{myCheckbox.selected}"/>

最佳答案

我认为这应该对你有用,YourTypeHere将是包含的类 对象,请确保 ShowImage 属性是公共(public)且可绑定(bind)的。

<mx:itemRenderer>
     <mx:Component> 
     <mx:Script>
        <![CDATA[ 
            import YourTypeHere;
        ]]>
    </mx:Script>
       <mx:Label text="{data}"/>
       <mx:Image id="img" 
        visible="{YourTypeHere(this.parent.ShowImage)}" 
        includeInLayout="{YourTypeHere(this.parent.ShowImage)}"/>
    </mx:Component>
</mx:itemRenderer>

P.s.请不要以大写字母开头的属性命名,包括 getter,请考虑将其命名为 showImage 并将您的私有(private)变量命名为 _showImage 之类的名称:D

关于apache-flex - Adobe Flex 4.5 Spark : Binding ItemRenderer Component to Parent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6682857/

相关文章:

actionscript-3 - 有没有办法禁用 ColorPicker 的左/右键盘箭头?

java - 如何强制用户更新应用?

apache-flex - ItemRenderer 改变背景颜色

apache-flex - 在Adobe Flex中为数据网格行设置背景色

c# - WCF 休息 : What is it expecting my XML to look like in requests?

apache-flex - 是否可以在 flex/as3 中访问父类(super class)的父类(super class)?

actionscript-3 - 仅增加一个 ItemRender 的高度

apache-flex - 如何在运行时获取控件的类型?

actionscript-3 - 根据 Flex 中的多个条件更改数据网格单元格的背景颜色

ios - 适用于 Flex mobile\iOS 的轻量级数据网格组件?