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
...
}
3 回答
您可以使用
getSource()
和getParent()
方法向上走控制层次结构,如下所示:无论如何,依赖于这样的层次结构对我来说似乎有点脆弱,很想看到一个更优雅的例子 .
我有或多或少相同的问题,但使用RowRepeater控件而不是表 . 看看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应该包含绑定到该行的对象,并包含您需要的所有值 .