SAPUI5:如何在控制器中使用外部库? [英] SAPUI5: How to use external library in controller?
本文介绍了SAPUI5:如何在控制器中使用外部库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的 index.html 文件中,我有以下代码:
In my index.html file I have the following code:
<script>
sap.ui.getCore().attachInit(function() {
jQuery.sap.registerModulePath("lodash","https://cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min");
jQuery.sap.require("lodash");
new sap.m.Shell({
app: new sap.ui.core.ComponentContainer({
height : "100%",
name : "sap.com.ml.docservicedoc-service-m-learning"
})
}).placeAt("content");
});
我现在如何在我的一个控制器(不是视图)中使用 lodash?我试过了:
How can I now use lodash in one of my controllers (not view)? I tried:
sap.ui.define([
"sap/ui/core/mvc/Controller",
"lodash"], function(Controller, _) {
不幸的是,_"总是未定义的.
Unfortunately "_" is always undefined.
推荐答案
想出了一个解决方案:
- 在您的项目中创建
libs
文件夹并将库放入该文件夹中 - 在您的控制器中添加如下库.还要记住,define 函数中的值应该与库的全局名称不同:
- Create
libs
folder in your project and put the library into that folder - Inside your controller add the library as the following. Also keep in mind that the value in the define function should be different to the global name of the library:
sap.ui.define([
"sap/ui/core/mvc/Controller",
"<project namespace>/libs/lodash/lodash.min",
], function(Controller, lodash) {
- 使用库的全局根变量.在 lodash 的情况下,它是_"
这篇关于SAPUI5:如何在控制器中使用外部库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文