问题
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");
});
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.
回答1:
Figured out a solution:
- 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) {
- Use global root variable of library. In case of lodash it is "_"
来源:https://stackoverflow.com/questions/46464218/sapui5-how-to-use-external-library-in-controller