我有一列链接。我希望每个链接在单击时在弹出框中显示不同的信息。我怎么能做到这一点?
这是我创建的专栏:
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();
}
这会创建一个打开的对话框,但每个链接都提供相同的信息,我希望每个链接都提供不同的信息。
答案 0 :(得分:1)
通常,您可以将按事件的事件处理程序附加到链接,并在事件处理程序中打开一个弹出窗口。链接的文本可以通过以下方式获得:
onLinkPressed : function(event) {
var link = event.getSource();
var email = link.getText();
}
答案 1 :(得分: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();
}