how to load external libraries into an SAP UI5 view?

北慕城南 提交于 2020-01-05 07:31:59

问题


In SAP UI5 I can load local files this way:

jQuery.sap.require("util.someFile"); 

But is it possible to load external libraries when required in some view using the above command or a similar approach? Ideally, I am looking for something like:

theLoadingCommand("some_url"); 

Thanks


回答1:


Basically it is possible to register a module path to some URL.

jQuery.sap.registerModulePath('external.library', 'http://....'); //not working

There is only one problem with that. UI5 loads the resources via AJAX requests. Your browser will give you an error because you are trying to load files from a different host.

You can include external libraries by including the file in a normal script tag. It is also possible to include requireJS in your project and use its features. Unfortunately, at the moment UI5 doesn't support requireJS out of the box.




回答2:


jQuery is supported by SAPUI5, so you can extend your heading from controller, for example:

var s = document.createElement("script");
s.type = "text/javascript";
s.src = "http://somedomain.com/somescript";
$("head").append(s);


来源:https://stackoverflow.com/questions/18984423/how-to-load-external-libraries-into-an-sap-ui5-view

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!