当我按下一个表项时,我想触发“handleRowPress”。 这是我的代码:
showTable: function(){
var oData=convertDataTable(testDataInput);
//make sure table id suffix is set (this is necessary for personalization)
var oTable = new sap.m.Table('testTable', {
headerToolbar: new sap.m.Toolbar({
itemPress: "alert('pippo')",
content: [
new sap.m.ToolbarSpacer({})
]
})/*,
columns: oData.cols.map(function (colname) {
//make sure column id suffix is set
return new sap.m.Column(colname, { header: new sap.m.Label({ text: colname })});
})*/
});
oTable.setModel(new sap.ui.model.json.JSONModel(oData));
for(var i=0; i<oTable.getModel().getProperty("/cols").length; i++){
oTable.addColumn(new sap.m.Column(oTable.getModel().getProperty("/cols")[i], { header: new sap.m.Label({ text: oTable.getModel().getProperty("/cols")[i] })}));
}
oTable.bindAggregation("items", "/items", new sap.m.ColumnListItem({
cells: oTable.getModel().getProperty("/cols").map(function (colname) {
return new sap.m.Label({ text: "{" + colname + "}" });
})
}));
//oTable.setProperty("selectionChange","handleRowPress");
//oTable.setProperty("itemPress", "handleRowPress" );
//oTable.setProperty("select", "handleRowPress" );
oTable.attachItemPress("handleRowPress");
var myPage=this.byId("pageOperation");
myPage.addContent(oTable);
},
handleRowPress : function(){
console.log("clicked on item!!!!");
//console.log(event);
}
为什么我不能这样做? 如果我尝试设置属性“itemPress”(注释行),它似乎没有设置它。
如何在没有XML视图的情况下设置功能,但只能使用js
代码?
答案 0 :(得分:0)
您可以将table-constructor中的处理程序设置为函数:
var oTable = new sap.m.Table({
itemPress: function(){
console.log("clicked on item");
}
});
或在构造函数中将其设置为引用
var oTable = new sap.m.Table({
itemPress: this.handleRowPress
});
或将函数附加到创建的Table-object
上oTable.attachItemPress(this.handleRowPress);