2010-07-19 133 views
1

我有一個數據網格,其中一列調用一個自定義itemEditor像;Flex:將一個參數傳遞給itemEditor

    <mx:DataGridColumn dataField="city" 
             width="150" 
             headerText="City" 
             itemEditor="components.ComboCity" 
             editorDataField="city"/> 

而我的自定義itemEditor看起來像;

<?xml version="1.0" encoding="utf-8"?> 
    <s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx" 
           focusEnabled="true"> 
     <mx:ComboBox id="comboBox"/> 
     <fx:Script> 
      <![CDATA[ 
       public var myString:String; 
       . 
       . 
       . 

我該如何從我的主應用程序傳遞一個值到myString

回答

1

對我來說,最好的解決辦法:

<mx:Script> 
    <![CDATA[ 

     import mx.events.DataGridEvent; 

     private function itemEditorCreateHandle(event:DataGridEvent):void 
     {    
      ComboCity(DataGrid(event.target).itemEditorInstance).myString = "Put here the value"; 
     } 

    ]]> 
</mx:Script> 

<mx:DataGridColumn  
    dataField="city" 
    width="150" 
    headerText="City" 
    itemEditor="components.ComboCity" 
    itemEditorCreate="itemEditorCreateHandle(event);" 
    editorDataField="city"/>