首页 文章

如何在没有实际选择sapui5中的表行的情况下获取行详细信息

提问于
浏览
2

我在sapui5中创建了一个表,其中数据从后端填充,即SAP Gateway . 我在表中添加了一个包含链接的列 . 每行都有一个链接 . 如果我点击该链接,则会打开一个弹出框 . 我想传递在弹出框中选中其链接的同一行的其他列的详细信息 . 为了获得详细信息,我需要该行的索引,我不知道 .

怎么实现呢?

3 回答

  • 1

    您可以使用 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
       ...
    }
    

    无论如何,依赖于这样的层次结构对我来说似乎有点脆弱,很想看到一个更优雅的例子 .

  • 0

    我有或多或少相同的问题,但使用RowRepeater控件而不是表 . 看看https://stackoverflow.com/a/21600210/3270057提供的答案Jasper_07

    这将使您可以访问当前绑定上下文属性或整个对象

    希望这可以帮助!

  • 1

    获取绑定到表的模型

    var model=that.getView().getModel("ModelName"); var path = evt.getSource().getParent().getBindingContextPath(); var data=model.getProperty(path);

    data应该包含绑定到该行的对象,并包含您需要的所有值 .

相关问题