我在 sapui5 中创建了一个表,其中数据从 SAP 网关的后端填充。我在表中添加了一个包含链接的列。每行都有一个链接。如果我单击该链接,则会打开一个弹出框。我想传递在弹出框中选择了链接的同一行的其他列的详细信息。为了获得详细信息,我需要我不知道的那一行的索引。
如何实现呢?
您可以使用getSource()
和getParent()
方法来向上遍历控件层次结构,如下所示:
function linkPressListener(oEv) {
// get event source -> the link
var link = oEv.getSource();
// walk up the control hierarchy until you reach the table row (1st parent should be column, 2nd the row)
var row = link.getParent().getParent();
// get the rows index
var index = row.getIndex();
// get row context from the table
var myTable = sap.ui.getCore().byId("myTablesID");
myTable.getContextByIndex(index);
// open your dialog using the rows context
...
}
无论如何,取决于这样的层次结构对我来说似乎有点脆弱,希望看到一个更优雅的例子。
我有或多或少相同的问题,但使用 RowRepeater 控件而不是 Table。查看https://stackoverflow.com/a/21600210/3270057提供的答案 Jasper_07
这将使您可以访问当前的绑定上下文属性或整个对象
希望这可以帮助!
获取已绑定到表的模型
var model=that.getView().getModel("ModelName");
var path = evt.getSource().getParent().getBindingContextPath();
var data=model.getProperty(path);
data 应该具有您已绑定到该行的对象并包含您需要的所有值。