[英]Flex switch item-renderer
I was wondering if anyone had any luck with the following senario in flex. 我想知道是否有人对以下Senario感到幸运。
I'd like to be able to have a custom item renderer which delegates to another renderer inside. 我希望能够有一个自定义项目渲染器,该渲染器将委托给另一个渲染器。
The reason for this would be in a datagrid for instance displaying a checkbox if the dataprovider for the row had a boolean value. 这样做的原因是在数据网格中,例如,如果该行的数据提供者具有布尔值,则显示一个复选框。 Using the default item renderer when the value was a non boolean.
当值是非布尔值时,使用默认项目渲染器。
Basically I was hoping to use a proxy object (though not necessarily the proxy class) so that I could a renderer which delegated all of its responsibilties to a sub renderer. 基本上,我希望使用代理对象(尽管不一定是代理类),以便我可以将其所有职责委托给子渲染器的渲染器。
Hard to explain. 难以解释。
Edit 1 编辑1
I think the following gives a clearer idea of what I had in mind. 我认为以下内容可以更清楚地了解我的想法。 This is only knocked up quickly for the purpose of showing the idea.
这只是为了展示这个想法而迅速提出来。
SwitchingRenderer.as SwitchingRenderer.as
package com.example
{
import mx.controls.CheckBox;
import mx.controls.dataGridClasses.DataGridItemRenderer;
import mx.controls.listClasses.BaseListData;
import mx.controls.listClasses.IDropInListItemRenderer;
import mx.core.IDataRenderer;
import mx.core.UIComponent;
public class SwitchingRenderer extends UIComponent implements IDataRenderer, IDropInListItemRenderer
{
private var checkboxRenderer:CheckBox;
private var defaultRenderer:DataGridItemRenderer;
private var currentRenderer:IDataRenderer;
public function SwitchingRenderer()
{
this.checkboxRenderer = new CheckBox();
this.defaultRenderer = new DataGridItemRenderer();
this.currentRenderer = defaultRenderer();
super();
}
public function get data():Object
{
//If the data for this cell is a boolean
// currentRender = checkBoxRenderer
// otherwise
// currentRenderer = defaultRenderer
}
public function set data(value:Object):void
{
currentRenderer.data = value;
}
public function get listData():BaseListData
{
return currentRenderer.listData;
}
public function set listData(value:BaseListData):void
{
currentRenderer.listData = value;
}
}
}
If you're using Flex 4 spark components look into the itemRendererFunction, 如果您使用的是Flex 4 Spark组件,请查看itemRendererFunction,
Here is a good sample from the interwebs. 这是来自互连网的一个很好的示例 。
Unfortunately, Flex 3 components, such as the DataGrid do not support that. 不幸的是,Flex 3组件(例如DataGrid)不支持该组件。
You're a bit vague on what you'd be displaying if the data sent into the itemRenderer was not a Boolean value. 如果发送到itemRenderer中的数据不是布尔值,则对于要显示的内容有点不确定。 But, you can easily modify the visual appearance of a component based on the data change event, including swapping visible properties of a component's children, changing states or change the selectedIndex of a ViewStack.
但是,您可以根据数据更改事件轻松地修改组件的外观,包括交换组件子项的可见属性,更改状态或更改ViewStack的selectedIndex。 All these things can be done within an itemRenderer w/o issues.
所有这些事情都可以在没有问题的itemRenderer中完成。
Edit: 编辑:
Based on the user's additional posting, I'd add that what he is after can be done like this: 基于用户的其他发布,我要补充一点,他可以执行的操作如下:
public function get data():Object
{
if(this.data is Boolean){
checkBoxRenderer.visible = true;
defaultRenderer.visible = false;
} else {
checkBoxRenderer.visible = false;
defaultRenderer.visible = true;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.