在 Openui5 中按项目触发功能 [英] Fire a function on an item press in Openui5
本文介绍了在 Openui5 中按项目触发功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在按下表格项目时触发handleRowPress".这是我的代码:
I want to fire "handleRowPress" when I press a table item. This is my code:
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"(注释行),它似乎没有设置它.
Why can't I do it? If I try to set the property "itemPress" (comment lines) it doesn't seem to set it.
如何在没有 XML 视图的情况下仅使用 js
代码设置函数?
How can I set the function without an XML view but only with js
code?
推荐答案
您可以在 table-constructor 中将处理程序设置为函数:
you can set the handler in the table-constructor as function:
var oTable = new sap.m.Table({
itemPress: function(){
console.log("clicked on item");
}
});
或在构造函数中设置为引用
or set it in the constructor as reference
var oTable = new sap.m.Table({
itemPress: this.handleRowPress
});
或将函数附加到创建的 Table 对象上
or attach the function over the created Table-object
oTable.attachItemPress(this.handleRowPress);
这篇关于在 Openui5 中按项目触发功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文