2010-06-29 75 views
0

我有一個數據網格,裏面有一個組合框,在Flex中訪問項目渲染器的屬性

<mx:DataGrid editable="true" x="72" y="10" id="dataGrid" creationComplete="dataGrid_creationCompleteHandler(event)" dataProvider="{getAllResult.lastResult}" height="178" width="896"> 
     <mx:columns> 
      <mx:DataGridColumn headerText="STATUS" dataField="tooltip"/> 
      <mx:DataGridColumn headerText="CUSTOM" editable="false" width="250" labelFunction="meAdnan" > 
       <mx:itemRenderer> 
        <fx:Component className="myEditor2"> 
         <mx:VBox height="100%" > 
          <mx:ComboBox id="pickState" labelField="attname" 
              dataProvider="{parentApplication.getAllResult2.lastResult}" 
             > 
          </mx:ComboBox> 

         </mx:VBox> 
        </fx:Component>     
       </mx:itemRenderer> 
      </mx:DataGridColumn> 
     </mx:columns> 
    </mx:DataGrid> 

現在,當我想從itemrendered /組合框我用parentApplication.funcName但有關訪問的其他方式訪問什麼功能,我怎樣才能從itemRenderer的外部訪問組合框的屬性?我試圖myEditor2.pickState,但它現在正

回答

1

parentApplication將參照主Application類可能並不總是你打算訪問哪些 - 如果你的DataGrid是在擴展Canvas一個組成部分。使用outerDocument訪問itemRenderer的擁有文檔。所以它應該是outerDocument.funcName

直接訪問itemRenderer實例並不是一個好主意,因爲在您滾動列表等時會重用項目渲染器。因此,如果您獲得對第一行的渲染器實例的引用,並且向下滾動列表,實例(您認爲是第一行)現在可能代表第三或第五(或其他)行,具體取決於您滾動的行數。正確的方法是覆蓋public set data方法並根據數據從那裏操作。

也就是說,您可以使用indexToItemRenderer方法獲得對給定索引處當前項目渲染器的引用。將其轉換爲正確的類型(或將其分配給類型爲Object的變量)並閱讀其pickState屬性。