2009-10-15 88 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

相关问题