我正在尝试动态更改 SAP Fiori 标题,即在启动板启动后并单击我选择的应用程序后,应用程序的标题应根据我的需要进行更改。 我正在使用此文档页面作为指南 https://ui5.sap.com/1.54.3/docs/api//symbols/sap.ushell.ui5service.ShellUIService.html .
在我的 webapp/Component.js
中,我有我的 setAppTitle()
方法,它应该为应用程序设置一个新的自定义标题,并从 中调用>onAfterRendering()
webapp/view/S2Custom.controller.js
方法。
我不能直接从 webapp/Component.js
的 init()
方法中调用 setAppTitle()
的原因是因为我从 webapp/i18n/i18n.properties
获取我的标题,它在 Component.js
的 init()
期间尚未“加载” >.
为了避免在 Component.js
中使用类似 setTimeout(() => this.setAppTitle(sTitle), 6000)
的东西,我决定在 中调用它
方法。webapp/view/S2Custom.controller.js
的 code>onAfterRendering()
webapp/view/S2Custom.controller.js
onAfterRendering: function (oEvent) {
var sComponentId = sap.ui.core.Component.getOwnerIdFor(this.getView());
var oComponent = sap.ui.component(sComponentId);
var i18nModel = new sap.ui.model.resource.ResourceModel({
bundleName: "ui.s2p.srm.sc.blahblah.BlahBlahExtension.i18n.i18n"
});
var oResource = i18nModel.getResourceBundle();
var sTitle = oComponent.getModel("appModel").getProperty("/sMode") === "OUTBOX" ? oResource.getText("APP_ONE") : oResource.getText("APP_TWO");
this.getOwnerComponent().setAppTitle(sTitle);
},
webapp/Component.js
setAppTitle: function (sText) {
var sTitle = sText;
console.log("TEST: ", this.getService("ShellUIService")); // ERROR !!!
try {
this.getService("ShellUIService").then(function (oService) {
oService.setTitle(sTitle);
}, function (oError) {
jQuery.sap.log.error("Cannot get ShellUIService");
});
} catch (err) {
console.log("TEST - ERROR: ", err);
}
},
setAppTitle()
方法中的问题 - 控制台显示错误:
this.getService is not a function.
所以我进入了我的manifest.json
"sap.ui5": {
"_version": "1.2.0",
"services": {
"ShellUIService": {
"factoryName": "sap.ushell.ui5service.ShellUIService"
}
},
"dependencies": {
"minUI5Version": "1.28.5",
"libs": {}
},
我注意到 Web IDE 在包含 "services": {
的行上显示 Property "services"is not allowed 错误。
你能告诉我是什么导致了这个问题吗?我已经尝试在 Component.js
的 init()
方法中单独调用 this.getService("ShellUIService")
,不幸的是同样的错误
this.getService is not a function.
最佳答案
您必须使用旧的 UI5 版本。 API component.getService
仅从 1.37.0
开始可用:
您可以在应用程序中按 Ctrl+Left Alt+Shift+P 查看当前版本.
关于 Web IDE 错误信息..
I noticed Web IDE showed Property "services" is not allowed error on line which contains
"services": {
.
- 如果可能,将 UI5 资源更新为 currently supported versions 之一.
- 除了根
_version
,删除sap.app
、sap.ui5
中的所有其他_version
等.. - 根据表 AppDescriptor Release and SAPUI5 Version 将根
_version
设置为高于1.3.0
的值. - 重新加载 Web IDE。
关于javascript - 动态更改 SAP Fiori 标题时出现 "this.getService is not a function",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58031563/