SAPUI5/FIORI - SmartTable pressItem 事件未触发
SAPUI5/FIORI - SmartTable pressItem Event not triggered
我正在尝试为 sap UI5 中的 SmartTable 控件附加 itemPress 事件。视图在 XML 中定义并绑定到 OData。
<mvc:View
controllerName="myapp.controller.App"
...>
<App>
<pages>
<Page title="title">
<content>
<smartTable:SmartTable
id="kubas"
...
tableType="ResponsiveTable"
...>
</smartTable:SmartTable>
</content>
</Page>
</pages>
</App>
</mvc:View>
因为对于 ResponsiveTable,后面的 table 是 sap.m.Table 我试图在控制器的 onAfterRendering 事件中附加 itemPress 事件。它不起作用。然后我尝试覆盖 table 本身的 onAfterRendering 并附加事件 - 同样的效果,事件没有触发。
onAfterRendering : function(){
var tTable = this.byId("kubas");
var oTable = this.byId("kubas").getTable(); //sap.m.table
console.log(oTable.getMetadata().getName());
oTable.setMode(sap.m.ListMode.SingleSelectMaster);
oTable.onAfterRendering = function(){
console.log("OnAfterRendering");
this.attachItemPress(function(oEvent){
console.log("Pressed!!");
});
}
我在这里做错了什么,有什么建议吗?有没有办法在 XML 中为 SmartTable 注册它?我不想在 XML 视图中切换到 sap.m.table,而是保持原样。非常感谢您的帮助大师。
我认为如果没有 XML 中的 table 定义就没有机会这样做。但我想你可以省略 "columns" 聚合定义,并在 "items" 中只包含 "ColumnListItem" 和所需的事件处理程序(没有 "cells")。智能 Table 应该自动注入需要的 columns/cells.
那是因为项目是“不活跃”。检查文档 here
>
attachItemPress(oData?, fnFunction, oListener?): sap.m.ListBase
Attaches event handler fnFunction to the itemPress event of this sap.m.ListBase.
When called, the context of the event handler (its this) will be bound to oListener if specified, otherwise it will be bound to this sap.m.ListBase itself.
>
Fires when an item is pressed unless the item's type property is Inactive.
请使用以下代码,SmartTable
的 attachDataReceived
正在运行。
var fnItemPress = function(){alert("press")};
tTable.attachDataReceived(function(){
var aItems = oTable.getItems();
if(aItems.length === 0 ) return;
$.each(aItems, function(oIndex, oItem) {
oItem.detachPress(fnItemPress);
oItem.setType("Active");
oItem.attachPress(fnItemPress);
});
});
谢谢!
我正在尝试为 sap UI5 中的 SmartTable 控件附加 itemPress 事件。视图在 XML 中定义并绑定到 OData。
<mvc:View
controllerName="myapp.controller.App"
...>
<App>
<pages>
<Page title="title">
<content>
<smartTable:SmartTable
id="kubas"
...
tableType="ResponsiveTable"
...>
</smartTable:SmartTable>
</content>
</Page>
</pages>
</App>
</mvc:View>
因为对于 ResponsiveTable,后面的 table 是 sap.m.Table 我试图在控制器的 onAfterRendering 事件中附加 itemPress 事件。它不起作用。然后我尝试覆盖 table 本身的 onAfterRendering 并附加事件 - 同样的效果,事件没有触发。
onAfterRendering : function(){
var tTable = this.byId("kubas");
var oTable = this.byId("kubas").getTable(); //sap.m.table
console.log(oTable.getMetadata().getName());
oTable.setMode(sap.m.ListMode.SingleSelectMaster);
oTable.onAfterRendering = function(){
console.log("OnAfterRendering");
this.attachItemPress(function(oEvent){
console.log("Pressed!!");
});
}
我在这里做错了什么,有什么建议吗?有没有办法在 XML 中为 SmartTable 注册它?我不想在 XML 视图中切换到 sap.m.table,而是保持原样。非常感谢您的帮助大师。
我认为如果没有 XML 中的 table 定义就没有机会这样做。但我想你可以省略 "columns" 聚合定义,并在 "items" 中只包含 "ColumnListItem" 和所需的事件处理程序(没有 "cells")。智能 Table 应该自动注入需要的 columns/cells.
那是因为项目是“不活跃”。检查文档 here
> attachItemPress(oData?, fnFunction, oListener?): sap.m.ListBase Attaches event handler fnFunction to the itemPress event of this sap.m.ListBase. When called, the context of the event handler (its this) will be bound to oListener if specified, otherwise it will be bound to this sap.m.ListBase itself.
> Fires when an item is pressed unless the item's type property is Inactive.
请使用以下代码,SmartTable
的 attachDataReceived
正在运行。
var fnItemPress = function(){alert("press")};
tTable.attachDataReceived(function(){
var aItems = oTable.getItems();
if(aItems.length === 0 ) return;
$.each(aItems, function(oIndex, oItem) {
oItem.detachPress(fnItemPress);
oItem.setType("Active");
oItem.attachPress(fnItemPress);
});
});
谢谢!