【发布时间】:2019-04-17 22:52:23
【问题描述】:
我在 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");
}
});
});
【问题讨论】:
-
在没有导入 amcharts 库的情况下是否可以工作?我不知道 amcharts,但如果 amCharts 全局定义或不支持 amd,你最好将它们加载到清单的
resources部分。 -
是的。你能告诉我如何在清单中加载它们吗?我不知道这是可能的吗?