在 SAPUI5 的 JSView 中,将当前控件引用传递给格式化函数非常容易:
oTable.bindItems("/rows", new sap.m.ColumnListItem({
cells : [ new sap.m.Text().bindProperty("text", {
parts: [
{ path: "someInteger" }
],
formatter: function(iValue) {
var idText = this.getId(); //this references the current control
return iValue;
}
})]
}));
Run Code Online (Sandbox Code Playgroud)
(当然,“简单”部分是因为this
在控件的内部格式化程序函数中引用了)
但是,对于 XMLViews,我还没有设法在格式化程序函数中获取对当前控件的引用:
<Table items="{/rows}">
<columns>
<Column>
<Text text="Some Integer" />
</Column>
</columns>
<items>
<ColumnListItem>
<cells>
<Text text="{ path : 'someInteger', formatter : '.formatCell' }" />
</cells>
</ColumnListItem>
</items>
</Table>
Run Code Online (Sandbox Code Playgroud)
和格式化程序:
formatCell : function (sValue) {
var a = this; //this references the controller
return sValue;
}
Run Code Online (Sandbox Code Playgroud)
有人知道如何在 XMLViews 中实现此功能吗?
在单独的文件中定义格式化程序函数。然后this
将是其属性正在被格式化的控件。
我的/自己的/Formatter.js:
sap.ui.define(function () {
"use strict";
return {
formatCell: function (iValue) {
var idText = this.getId(); //this references the current control
return iValue;
}
};
});
Run Code Online (Sandbox Code Playgroud)
看法:
<Table items="{/rows}">
<columns>
<Column>
<Text text="Some Integer" />
</Column>
</columns>
<items>
<ColumnListItem>
<cells>
<Text text="{ path : 'someInteger', formatter : 'my.own.Formatter.formatCell' }" />
</cells>
</ColumnListItem>
</items>
</Table>
Run Code Online (Sandbox Code Playgroud)