在SAPUI5中加载amcharts库-component.js与index.html

时间:2019-04-17 22:52:24

标签: sapui5 amcharts

我无法在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

error in launchpad

所以我的问题是,是否需要在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");
        }
    });
});

1 个答案:

答案 0 :(得分:0)

在清单的sap.ui部分中,您将找到resources的条目。通常,它只有一个CSS文件,但是您也可以定义外部javascript库。如果您要加载多个依赖项,请确保将它们排序

    "resources": {
        "js": [{
            "uri": "libs/mylib.js"
        }],
        "css": [{
            "uri": "css/style.css",
            "id": "style"
        }]
    }

如果一切顺利,您将只能使用window.amChart或它们的全局对象称为