我看到这个例子: https://openui5.hana.ondemand.com/#docs/guide/25ab54b0113c4914999c43d07d3b71fe.html
我有格式化程序功能:
rowVisibility: function (oRow, sGrid) {
var oModel = new sap.ui.model.json.JSONModel();
oModel.loadData("model/file/mapping/map.json", "", false);
var oGridInfo = oModel.getProperty("/elements")[sGrid];
var bVisible = true;
_.forEach(oGridInfo.fields, function (fld) {
if (oRow[fld] == null)
bVisible = false;
});
return bVisible;
}
在XML视图中,我尝试传递多个参数:
visible="{parts:[{path: 'model>'}, {'MY_GRID_NAME'} ], formatter:'ui5bp.Formatter.rowVisibility'}"
但它不起作用...... 我该如何发送sGrid param?我想只创建一个格式化程序函数,而不是每个sGrid都有一个!
示例:从3个不同的上下文(“context_a”,“context_b”和“context_c”)调用rowVisibility formatter函数。我想要从3个上下文调用一个函数(行为将根据上下文而不同)
visible="{parts:[{path: 'model>'}, {"context_a"} ], formatter:'ui5bp.Formatter.rowVisibility'}"
visible="{parts:[{path: 'model>'}, {"context_b"} ], formatter:'ui5bp.Formatter.rowVisibility'}"
visible="{parts:[{path: 'model>'}, {"context_c"} ], formatter:'ui5bp.Formatter.rowVisibility'}"
这是唯一的功能
rowVisibility: function (oRow) {
...
}
现在我有3种不同的功能:
rowVisibility_contextA: function (oRow) {
...
}
rowVisibility_contextB: function (oRow) {
...
}
rowVisibility_contextC: function (oRow) {
...
}
答案 0 :(得分:0)
你在做哪个控制?可见' property通常是一个布尔值;如果您尝试为其设置非布尔值,则会出现错误。
答案 1 :(得分:0)
请更正您的语法。检查此link。你想念'路径'对于“MY_GRID_NAME”'
答案 2 :(得分:0)
我不相信在使用扩展语法时可以使用字符串文字或变量。我使用的一种解决方法是将值存储在模型中,然后使用它 - 它有点难看,但它有效(并且比使用大量的包装器格式化函数来满足每种情况要好得多)。
答案 3 :(得分:0)
在 @mjturner 的答案基础上,我需要做到这一点。我本来希望将字符串文字放在parts
部分中,但使用视图JSONModel
也可以满足我的需求。
让我说我的messageBundle.properties
文件中有这个i18n条目:
Main.IconTabFilter.StatusExpandedMessage=Filtering on {0} projects ...
然后,我在BaseController
的{{1}}课程中设置了这个格式化程序功能:{/ 1}}
sap.ui.core.mvc.Controller
然后从您的视图控制器中设置视图 /**
* Generic function to format i18n strings given data from XML views. This is a convenience method.
*
* @param {string} sKey - this is the i18n key in your messageBundle to use. !!! IMPORTANT !!! this key must be sent through
* a model (like View JSONModel). You cannot pass string literals in the <code>{ parts: [] }</code> array in XML.
* @param {string} [dynamic] - This function accepts any number of strings (parts) to add to i18n string.
* These dynamic strings are added to i18n with <code>Array.prototype.slice.call(arguments, 1)</code>.
*/
i18nFormatter: function(sKey) {
if (sKey) {
return this.getResourceBundle().getText(sKey, Array.prototype.slice.call(arguments, 1));
} else {
return null;
}
}
(或使用现有的):
JSONModel
既然格式化程序具有检索数据的所有方法,那么让我们设置XML视图:
var oViewModel = new JSONModel({
i18n: {
StatusExpandedMessage: 'Main.IconTabFilter.StatusExpandedMessage'
}
});
this.getView().setModel(oViewModel, 'view');
您可以在任何想要执行此操作的位置重复使用此格式化程序。只要始终确保您的第一部分&#39;是您的i18n消息的字符串键。