DataGrid中itemRender的用法--解决item中组件显示的问题

 

我在DataGrid中要显示一列图片,于是用了itmTender包含了一个类:


<mx:itemRenderer>
          <mx:Component>
          <mx:VBox paddingLeft="10">
           <component:imageComponent id="iconimage2" x="15" imageData="{data.purview_name}"/>
           </mx:VBox>
          </mx:Component>
         </mx:itemRenderer>

 

但出现了每次刷新数据源,里面的图片会变乱的情况,解决办法是:

 

<mx:itemRenderer>
          <mx:Component>
          <mx:VBox paddingLeft="10">
           <!--component:imageComponent id="iconimage2" x="15" imageData="{data.purview_name}"/-->
           <mx:Script>
                         <![CDATA[
                             override public function set data( value:Object ) : void {
                                 super.data = value;
                             }
                             private function imgsource(str:String):String
                                 {
                                 switch(str)
          {
           case "Guild Leader":str = "../images/new_guilds/icon_Crown.png";//str= "首领";
                break;
           case "Guild Master":str = "../images/new_guilds/icon_Badge.png";//str= "管理";
                break;
           case "Guild Moderator":str = "../images/new_guilds/icon_Ring.png";//str= "仲裁";
                break;
           case "Guild Member":str = "false";
                break;
          }
          return str;
                                 }
                         ]]>
                         </mx:Script>
                         <mx:Image source="{imgsource(data.purview_name)}" visible="{imgsource(data.purview_name)!='false'?true:false}"/>
          </mx:VBox>
          </mx:Component>
         </mx:itemRenderer>

 

关于itemRender的学习请见:

http://www.adobe.com/devnet/flex/articles/itemrenderers_pt1.html

你可能感兴趣的:(datagrid,function,String,object,image)