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

时间:2014-03-24 00:38:13

标签: sapui5

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

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,我不知道怎么做?

谢谢

2 个答案:

答案 0 :(得分:4)

如果您要绑定数据,请尝试

this.getBindingContext(/*modelName?*/)

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

答案 1 :(得分:-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];