【问题标题】:jQuery.sap.includeScript().then() not working in SCP SAPUI5 appjQuery.sap.includeScript().then() 在 SCP SAPUI5 应用程序中不起作用
【发布时间】:2021-01-07 05:11:27
【问题描述】:

我正在尝试在 sapui5 中包含 googlemaps

jQuery.sap.includeScript({
                url: "https://maps.googleapis.com/maps/api/js?key=XXXX",
                promisify: true
            }).then(function() { ... } )

当我在 SAP Web-IDE Trial 中运行时,这个 Promise 工作正常,但是当我将它部署到 hana 云平台时,它不起作用:

InterceptService.js:1 Uncaught (in promise) TypeError: u.indexOf is not a function(...) sap.ushell.cloudServices.interceptor.InterceptService._invokeFilters@InterceptService.js:1

jQuery.sap.includeScript@InterceptService.js:1

onAfterRendering@Worklist.controller.js:37

InterceptService.js 产生此错误的代码片段是

{if(u.indexOf('/sap/fiori/../../')>0){u=u.replace('/sap/fiori/../../','/');}

我确实使用 HCP 门户服务 来制作 HCP Fiori Launchpad 平台。

如何解决这个问题?我做错了什么?

非常感谢!

【问题讨论】:

  • 你不需要传递promisify: true,因为它被UI5忽略了
  • 根据经验,您仍然需要使用回调“当 API 准备就绪时,它将调用使用回调参数指定的函数。” developers.google.com/maps/documentation/javascript/tutorial
  • 谢谢@Jasper_07 这两种方法我都试过了。但是我使用的是xml视图,所以使用google推荐的方式不太方便(我不知道如何将init函数放在另一个模块中)。而且我没有看到使用 openui5-googlemaps 的必要性......我已经受够了 xml 视图。

标签: sapui5 sap-fiori sap-cloud-platform


【解决方案1】:

确实是InterceptorService的问题,不支持includeScript的语法,第一个参数是object。

我已将解决方案的代码转发给HCP Portal Service的实施团队,并将在下一个版本中修复。

到目前为止,您可以通过以下解决方法实现相同的功能:

new Promise(function(fnResolve, fnReject) {
    jQuery.sap.includeScript(
        "https://maps.googleapis.com/maps/api/js?key=XXXX", 
        "mapsScriptId", fnResolve, fnReject
    );
}).then(function() { ... } )

看看 UI5 是如何实现的: https://github.com/SAP/openui5/blob/rel-1.38/src/sap.ui.core/src/jquery.sap.global.js#L4387-L4389

【讨论】:

  • 嗨瓦迪姆,很棒的答案!您能否详细解释一下为什么“InterceptorService”会对“includeScript”产生影响?我认为只有浏览器才能解决这些功能。欢迎任何帮助或材料。
【解决方案2】:

看起来 InterceptService 还不支持 jQuery.sap.includeScript 的最新签名(其中参数在配置对象中提供,而不是作为单个参数提供)。

期中,InterceptService 需要增强/修复。短期内,您可能会退回到旧签名jQuery.sap.includeScript(url, id, onload, onerror)。不幸的是,没有办法使用旧签名获得 Promise。

【讨论】:

    猜你喜欢
    • 2017-07-26
    • 1970-01-01
    • 2013-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-03
    • 1970-01-01
    • 2017-04-14
    相关资源
    最近更新 更多