共计 1213 个字符,预计需要花费 4 分钟才能阅读完成。
步骤 1:在 manifest.json 的 extends 区域里,注册 controllerExtensions:
源代码:
"extends": {
"extensions": {
"sap.ui.controllerExtensions": {
"sap.suite.ui.generic.template.ListReport.view.ListReport": {
"controllerName": "com.sap.jerry.jerryfioriapp.ext.controller.ListReportExtension",
"sap.ui.generic.app": {
"SEPMRA_C_PD_Product": {
"EntitySet": "SEPMRA_C_PD_Product",
"Actions": {
"ActionName1": {
"id" : "ActionName1",
"text" : "Jerry 的按钮",
"press" : "onCustomAction1",
"global": true
}
}
}
}
}
}
}
},
步骤 2:
实现 controller extension:
sap.ui.define("com.sap.jerry.jerryfioriapp.ext.controller.ListReportExtension", [], function() {
return {onCustomAction1 : function(oEvent) {alert('Hello');
},
onAfterRendering: function (oEvent) {
debugger;
var oContentTable = this.byId("com.sap.jerry.jerryfioriapp::sap.suite.ui.generic.template.ListReport.view.ListReport::SEPMRA_C_PD_Product--responsiveTable");
oContentTable.attachSelect(this._onSelectChanged);
},
_onSelectChanged: function (oEvent) {debugger;}
}
});
步骤 3:测试。
运行时,首先触发 onAfterRendering 钩子函数,通过 byId API,依据 Smart Table 控件 ID,拿到其 table 实例:
SAP UI5 里所有的运行时创立实例,都存储在全局对象 mInstances 里,键为 控件 id,值为控件实例。
拿到 table 实例后,调用其 attach 办法,挂接对应的事件处理函数。
所有实现后,点击 Smart Table 某行我的项目,咱们应用 attachSelect 注册的事件处理函数就会触发:
本文参考:Fiori Element List Report – Adjust column size automatically
更多 Jerry 的原创文章,尽在:” 汪子熙 ”:
正文完