如何在sap.m.table中获取行的内容

问题描述 投票:6回答:2

所以基本上我的问题是我有一个页面:

var page1 = new sap.m.Page({
title: "Something", 
enableScrolling : true, 
content : [
    oTable = new sap.m.Table("items", {
        columns : [
            new sap.m.Column({
                styleClass : "name",
                hAlign : "Left",
                header : new sap.m.Label({
                    text : "firstColumn"
                })
            })
        ]
    })]
});
var template = new sap.m.ColumnListItem({
    type : "Navigation",
    cells : [
        new sap.m.Label({
            text : "{name}"
        })
    ]
});
template.attachPress(function(oEvent){
    var selectedRowContext = oEvent.getParameter("item");
    alert(selectedRowContext);
});

在这里,我想获得selectedRowContext,我不知道如何?

谢谢

sapui5
2个回答
4
投票

如果你是绑定数据试试

this.getBindingContext(/*modelName?*/)

要么

oEvent.getSource().getBindingContext(/*modelName?*/)

-1
投票
//oControlEvent is the argument from the attachpress event    
     var selectedData = oControlEvent.getParameters().rowBindingContext.getModel().getData();
            var selectedPath = oControlEvent.getParameters().rowBindingContext.getPath();
            var selectedIndex = selectedPath.split("/")[selectedPath.split("/").length - 1];
            selectedData = selectedData[OBJECTNAME][selectedIndex];
© www.soinside.com 2019 - 2024. All rights reserved.