工厂
package com.gwtjs.renderer.grid { import mx.core.IFactory; //必须要实现IFactory接口 public class EnableItemIFactory implements IFactory{ public function EnableItemIFactory(){ super(); } public function newInstance():*{ //实例化渲染器,实现具体功能 return new EnableItemRenderer(); } } }
视图
<?xml version="1.0" encoding="utf-8"?> <mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" backgroundAlpha="0.0" width="100%" horizontalAlign="center"> <!-- 使用参考: [Bindable] //定义渲染器 - 是否 private var enabledRender:IFactory = new EnableItemIFactory(); <mx:DataGridColumn datafield="enabled" headerText="是否启用" width="86" itemRenderer="{enabledRender}" /> --> <mx:Style> .upText{color:#00661A; textAlign:right;} .downText{color:#FF0000; textAlign:right;} </mx:Style> <mx:Script> <![CDATA[ [Embed(source='assets.png')] private static const tick:Class; [Embed(source='assets.png')] private static const cross:Class; [Bindable] private var class_name:String; private function getimage(data:Object):Object {if('1'==data.enabled||true==data.enabled||'true'==data.enabled||1==Number(data.enabled)){ class_name='upText'; return tick; }else{ class_name='downText'; return cross; } } public function getState(value:String):String{ if('1'==value){ return "是";//"../assets/images/icon/user_female.png";} return "否";//"../assets/images/icon/user_suit.png"; }]]> </mx:Script> <mx:Image id="stateImage" source="{getimage(this.data)}"/> </mx:HBox>
引用:
[Bindable] //定义渲染器 - 是否 private var enabledRender:IFactory = new EnableItemIFactory(); <mx:DataGridColumn datafield="enabled" headerText="是否启用" width="86" itemRenderer="{enabledRender}" />