首页 文章

Sapui5列的链接

提问于
浏览
0

我有一列链接 . 我希望每个链接在单击时在弹出框中显示不同的信息 . 我怎么能做到这一点?

这是我创建的列:

oControl = new sap.m.Link({ text: "{userEmails}" });
oTable.addColumn(new sap.ui.table.Column("userEmails", {
    label: new sap.m.Label({ text: "User Emails" }),
    template: oControl,
    sortProperty: "userEmails",
    filterProperty: "userEmails"
}));

我希望根据点击链接的行显示用户的电子邮件 .

编辑:这是我尝试过的:

onLinkPressed: function (oEvent) {
    var obj = oEvent.getSource().getBindingContext().getObject();
    var email = obj.email;
}

电子邮件是另一栏 . 当我点击链接时没有任何反应 .

EDIT2:我也试过这个:

oControl = new sap.m.Link({text: "{userEmails}", press: function() {openDialog();}});         // edited from the first line of code I posted

function openDialog() {
    var oDialog1 = new sap.ui.commons.Dialog();
    oDialog1.setTitle("My first Dialog");
    var oText = new sap.ui.commons.TextView({ text: "example@email.com" });
    oDialog1.addContent(oText);
    oDialog1.addButton(new sap.ui.commons.Button({ text: "OK", press: function () { oDialog1.close(); } }));
    oDialog1.open();
}

这会创建一个打开的对话框,但每个链接都提供相同的信息,我希望每个链接提供不同的信息 .

2 回答

  • 1

    通常,您可以将 press 事件的事件处理程序附加到链接,并在事件处理程序中打开一个弹出窗口 . 链接的文本可以如下获得:

    onLinkPressed : function(event) {
        var link = event.getSource();
        var email = link.getText();
    }
    
  • 0

    我终于想通了!这是我的工作代码:

    oControl = new sap.m.Link({ text: "{userEmails}", press: function (oEvent) { openDialog(oEvent);}});
    oTable.addColumn(new sap.ui.table.Column("userEmails", {
        label: new sap.m.Label({ text: "User Emails" }),
        template: oControl,
        sortProperty: "userEmails",
        filterProperty: "userEmails",
    
    }));
    
    function openDialog(oEvent) {
        var oDialog1 = new sap.ui.commons.Dialog();
        oDialog1.setTitle("Emails");
        var obj = oEvent.getSource().getBindingContext().getObject();
        var email = obj.email;
        var oText = new sap.ui.commons.TextView({ text: email });
        oDialog1.addContent(oText);
        oDialog1.addButton(new sap.ui.commons.Button({ text: "OK", press: function () { oDialog1.close(); } }));
        oDialog1.open();
    }
    

相关问题