【问题标题】:how to have a link in a datagrid and to pop up a window on clicking the link in flex?如何在数据网格中有一个链接并在单击 flex 中的链接时弹出一个窗口?
【发布时间】:2009-10-15 05:46:04
【问题描述】:

我有一个包含不同类型列的数据网格,比如我有复选框、组合框和文本输入作为列类型。

现在我想要一个链接类型的列,带有标签“视图”。该列中的所有行都带有相同的标签“查看”链接,单击它时,我想要打开一个弹出窗口?

这是我的代码:

<?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>

我不知道如何在数据网格中添加链接。所以使用Text控件来显示“View”标签。现在,如果我在数据网格中单击此项目“查看”,我希望调用弹出功能,即 defectCommentsPopUp()。

如何做到这一点?

【问题讨论】:

    标签: apache-flex datagrid


    【解决方案1】:

    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);
    }
    

    【讨论】:

    • 当你在 itemRenderer 中使用 mx:Component 标签声明 drop 时,你不能使用 this 关键字引用原始类的方法。这是因为在组件标签内this 指的是组件的根(在这种情况下是标签)。组件标签是避免为此类简单情况编写另一个 mxml 文件的快捷方式。 outerDocument 是一个变量,它引用了包含该组件的原始 mxml 文档。
    • 好的。我拥有此代码的 mxml 文件是 DefectEntryVerification。但如果我给&lt;mx:Label text="View" click="DefectEntryVerification.onViewClick(data)"/&gt; 它会显示错误:1061: Call to a possibly undefined method onViewClick through a reference with static type Class.
    • ClassName.method() 是调用静态方法的语法。对于实例方法,您使用实例名称或 this 关键字。 this 关键字在组件标签中不起作用,因此 outerDocument。阅读我之前的评论 |谷歌“flex itemrenderer externaldocument”
    • 好的,我现在明白了.. 我想我应该给出我的 mxml 组件的名称而不是 outerDocument 并且它都出错了.. 谢谢你的帮助...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多