2009-10-15 84 views
0

我有一個不同類型的列的數據網格,就像我有複選框,組合框和文本輸入作爲列類型。如何在數據網格中建立鏈接並在彈出的鏈接中彈出窗口?

現在我想要一個列類型的鏈接,標籤爲「視圖」。該列中的所有行都鏈接到相同的標籤「視圖」並點擊它,我想要打開一個彈出窗口?

這是我的代碼:

<?xml version="1.0" encoding="utf-8"?> 
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%"> 
<mx:Script> 
    <![CDATA[ 

     [Bindable] 
     private var defectDetails:ArrayCollection = new ArrayCollection([ ]); 

     private function addDefect():void{ 
      defectDG.dataProvider.addItem(
       {CommentHistory:"View"} 
      ); 
      defectDG.height += 30; 
     } 

     private function defectCommentsPopUp():void{ 
      var helpWindow:defectCommentsLookUp=defectCommentsLookUp(PopUpManager.createPopUp(this, defectCommentsLookUp, true)); 
     } 
    ]]> 
</mx:Script> 

<mx:DataGrid id="defectDG" dataProvider="{defectDetails}" variableRowHeight="true" width="100%" height="75" > 

<mx:columns> 

    <mx:DataGridColumn headerText="Select" dataField="Select" itemRenderer="mx.controls.CheckBox" width="50" textAlign="center" /> 

    <mx:DataGridColumn headerText="Defect Id" dataField="DefectId" itemRenderer="mx.controls.TextInput" textAlign="center"/> 

    <mx:DataGridColumn headerText="Status" dataField="Status" itemRenderer="mx.controls.ComboBox" textAlign="center"/> 

    <mx:DataGridColumn headerText="Severity" dataField="Severity" itemRenderer="mx.controls.ComboBox" textAlign="center" />  

    <mx:DataGridColumn headerText="Comment History" dataField="CommentHistory" itemRenderer="mx.controls.Text" textAlign="center" headerWordWrap="true" /> 

</mx:columns> 
</mx:DataGrid> 

<mx:Button styleName="buttonStyle" label="Add New Defect" click="addDefect()"/> 

</mx:VBox> 

我不知道如何把在DataGrid中的一個環節。所以使用了Text控件來顯示「View」標籤。現在,如果我點擊這個項目,在數據網格中「查看」,我想要彈出函數,即,調用defectCommentsPopUp()。

如何做到這一點?

回答

2

將值分配給commentHistory有助於識別該行。

<mx:DataGridColumn dataField="commentHistory"> 
    <mx:itemRenderer> 
    <mx:Component> 
     <mx:Label text="View" click="outerDocument.onViewClick(data)"/> 
    </mx:Component> 
    </mx:itemRenderer> 
</mx:DataGridColumn> 
腳本

private function onViewClick(item:Object):void 
{ 
    //item contains the commentHistory value of the clicked row. 
    showPopUp(item); 
} 
+0

笏是添加outerDocument? – Angeline 2009-10-15 07:41:30

+0

當您使用mx:Component標籤聲明itemRenderer的放置位置時,不能使用'this'關鍵字引用原始類的方法。這是因爲在組件標籤內,this指的是組件的根(在這種情況下是Label)。組件標記是避免爲此類簡單情況編寫另一個mxml文件的快捷方式。 'outerDocument'是一個變量,它指向包含該組件的原始mxml文檔。 – Amarghosh 2009-10-15 08:11:04

+0

好的。我有這個代碼的mxml文件是DefectEntryVerification。但是如果我給''mx:Label text =「View」click =「DefectEntryVerification.onViewClick(data)」/>'它顯示錯誤:'1061:通過靜態類型Class的引用調用onViewClick中可能未定義的方法。 ' – Angeline 2009-10-15 08:38:24

相關問題