2015-06-25 78 views
1

我有一個自定義的外部itemRenderer,我用它來顯示項目在MX:列表中。 dataProvider是一個數組,每個元素包含4個屬性。看起來好像itemRenderer實際上是獲取數組,因爲它顯示4個項目(數組中的項目數量),但項目顯示爲「[object Object]」。自定義外部itemRenderer正在從dataProvider接收空對象

這是我的itemRenderer ...

<mx:Metadata> 
    [Event(type="classes.events.RemoveEntryEvent", name="removeProject")] 
</mx:Metadata> 

<mx:Script> 
    <![CDATA[ 
     import classes.events.RemoveEntryEvent; 

     import mx.controls.Alert; 
     import mx.events.CloseEvent; 
     import mx.events.FlexEvent; 

     override public function set data (value:Object):void{ 
      super.data = value; 
      //Alert.show(value.toString()); 
     } 

     public function button_clickHandler():void { 
      var alertListener:Function = function(closeEvent:CloseEvent):void{ 
       if (closeEvent.detail == Alert.YES){ 
        //dispatchEvent(new RemoveEntryEvent(RemoveEntryEvent.REMOVE_PROJECT, true, false, data)); 
       } 
      } 

      var myAlert:Alert = Alert.show("Are you sure you want to remove yourself from this project?", 
       "Remove Project", 
       (Alert.YES | Alert.CANCEL), 
       null, alertListener); 

      myAlert; 
     }  

     private function text_clickHandler():void{ 
      Alert.show("inside text_clickHandler()"); 
     } 



    ]]> 
</mx:Script> 

<!-- The mx:Text should display a hand maybe when rolledOver: !buttonMode, --> 
<mx:Text id="text" width="85%" text="{data}" fontThickness="5" click="text_clickHandler()"/> 
<mx:Button id="removeButton" label="Remove" fontSize="9" width="63" verticalCenter="0" fontWeight="normal" x="329" 
      height="17" click="button_clickHandler()"></mx:Button> 


</mx:Canvas> 

當我通過一組數據功能步驟, '價值:對象' 爲空!但是,它再次顯示正確數量的項目。

這裏是我的MXML代碼中,我的MX:名單載...

<mx:TitleWindow y="10" width="550" height="342" layout="absolute" title="LIST OF PROJECTS" cornerRadius="4" id="listOfProjects_panel" horizontalCenter="0"> 
    <mx:List alternatingItemColors="{altColors}" x="65.5" y="30" width="399" height="232" backgroundColor="#F8F8F8" fontSize="12" dataProvider="{xmlSimpleArray}" 
          id="list_of_projects_master" initialize="listInitializer()" useRollOver="false" selectable="false"> 
    </mx:List> 
    <mx:Button y="270" label="Refresh List" width="130" x="334.5" id="auth_btn_master0" fontWeight="normal"/> 
    <mx:Label x="65.5" y="10" text="Click To Select A Project:" fontWeight="bold"/> 
</mx:TitleWindow> 

這裏是我的MX初始值設定:腳本...

private function listInitializer():void{ 
      //list_of_projects_master.dataProvider = xmlSimpleArray; 
      list_of_projects_master.itemRenderer = new ClassFactory(ProjectListRenderer); 
      list_of_projects_master.addEventListener(RemoveEntryEvent.REMOVE_PROJECT, updateXML); 
     } 

如果再信息需要評估問題,請讓我知道

+0

btw,這是我的數組.... [Bindable] \t public var xmlSimpleArray:Array; –

回答

1

在itemrenderer中更改以下行

<mx:Text id="text" width="85%" text="{data}" fontThickness="5" click="text_clickHandler()"/> 

建議立即進行刪除像

<mx:Text id="text" width="85%" text="{data.labelfieldname}" fontThickness="5" click="text_clickHandler()"/> 

希望這會有所幫助。

+0

是的,這工作!謝謝@krishnaja –

相關問題