我在SAPUI5中加载amcharts库时遇到问题。我想加载3个amCharts库,核心,图表和动画。我将它们放在我的项目结构中名为libs的文件夹中...请注意我想使用component.js文件而不是index.html,因为我的应用程序将从Fiori Launchpad启动。
经过一些很好的建议后,我现在将它们加载到manifest.json文件中,如下所示
"resources": {
"js": [
{
"uri": "libs/core.js"
},
{
"uri": "libs/charts.js"
},
{
"uri": "libs/animated.js"
}
],
"css": [
{
"uri": "css/style.css"
}
]
},
当我通过index.html文件测试应用程序...它的工作原理!
当我使用component.js文件测试时,我在控制台中收到以下错误
Failed to load resource: the server responded with a status of 404 ()
The issue is most likely caused by application znrw.amCharts. Please create a support incident and assign it to the support component of the respective application. - Failed to load UI5 component with properties: '{
"asyncHints": {
"waitFor": []
},
"name": "znrw.amCharts",
"url": "../../../../../webapp",
"id": "application-Test-url-component",
"componentData": {
"startupParameters": {}
},
"async": true
}'. Error likely caused by:
TypeError: Cannot read property '1' of null
所以我的问题是,我是否必须在component.js文件中添加一些内容才能加载库?或者我需要在manifest.json文件中做些什么?
目前,组件文件如下所示:
"sap/ui/core/UIComponent",
"sap/ui/Device",
"znrw/amCharts/model/models"
], function (UIComponent, Device, models) {
"use strict";
return UIComponent.extend("znrw.amCharts.Component", {
metadata: {
manifest: "json"
},
/**
* The component is initialized by UI5 automatically during the startup of the app and calls the init method once.
* @public
* @override
*/
init: function () {
// call the base component's init function
UIComponent.prototype.init.apply(this, arguments);
// enable routing
this.getRouter().initialize();
// set the device model
this.setModel(models.createDeviceModel(), "device");
}
});
});
在清单的sap.ui
部分,你会找到resources
的条目。通常它只有一个CSS文件,但你也可以定义外部JavaScript库。如果您正在加载多个从属的,请确保将它们整理好
"resources": {
"js": [{
"uri": "libs/mylib.js"
}],
"css": [{
"uri": "css/style.css",
"id": "style"
}]
}
如果一切顺利,您将能够使用window.amChart
或其他全局对象被调用