Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/433.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未捕获类型错误:无法读取属性';初始化';未定义的_Javascript_Exception_Sapui5_Instantiation - Fatal编程技术网

Javascript 未捕获类型错误:无法读取属性';初始化';未定义的

Javascript 未捕获类型错误:无法读取属性';初始化';未定义的,javascript,exception,sapui5,instantiation,Javascript,Exception,Sapui5,Instantiation,目前我正在进行一个升级项目;当我从Component.js实例化自定义路由器类时,我面临以下异常;特定于应用程序的配置在单独的manifest.json文件中配置。问题是我无法从Component.js读取manifest.json配置 我从零开始创建了SAP Ui5应用程序,通过SAP的最佳方法实现了这些应用程序,它们都运行良好,我甚至交叉检查了一个运行中的Ui5应用程序的清单文件,一切都很完美,但我仍然无法发现问题,我得到了以下例外 异常/错误: UIComponent.js:6 Uncau

目前我正在进行一个升级项目;当我从Component.js实例化自定义路由器类时,我面临以下异常;特定于应用程序的配置在单独的manifest.json文件中配置。问题是我无法从Component.js读取manifest.json配置

我从零开始创建了SAP Ui5应用程序,通过SAP的最佳方法实现了这些应用程序,它们都运行良好,我甚至交叉检查了一个运行中的Ui5应用程序的清单文件,一切都很完美,但我仍然无法发现问题,我得到了以下例外

异常/错误:

UIComponent.js:6 Uncaught TypeError: Cannot read property 'initialize' of undefined
    at f.init (Component.js:21)
    at f.constructor (sap-ui-core.js:135)
    at f.constructor (sap-ui-core.js:141)
    at f.constructor (UIComponent.js:6)
    at new f (sap-ui-core.js:135)
    at Object.sap.ui.component (sap-ui-core.js:141)
    at F.a.onBeforeRendering (ComponentContainer.js:6)
    at F.a._callEventHandles (sap-ui-core.js:147)
    at F.a._handleEvent (sap-ui-core.js:147)
    at t (sap-ui-core.js:147)
Component.js[请注意:下面我只共享了init方法]

sap.ui.define([
    "sap/ui/core/UIComponent",
    "xxxx/app/xxxxx/MyRouter"
], function (UIComponent , MyRouter ) {

    return  UIComponent.extend("xxxx.app.xxxxxx.Component", {

        metadata: {
            manifest: "json"
        },

    init : function() {
        debugger; // IMDK901184 
        UIComponent.prototype.init.apply(this, arguments);

        // I am getting the exception once the below line is executed.
        this.getRouter().initialize();  

    }
}
    });
});
manifest.json

{
    "_version": "1.12.0",
    "sap.app": {
        "id": "xxxxx.app.xxxxx",
        "type": "application",
        "i18n": "i18n/messageBundle.properties",
        "title": "xxxx",
        "description": "xxxx",
        "applicationVersion": {
            "version": "1.0.0"
        },
        "dataSources": {
            "mainService": {
                "uri": "xxxx.app.xxxxxx.AppScripts.config.baseURL",
                "type": "OData",
                "settings": {
                    "odataVersion": "2.0"
                }
            }
        }
    },
        "sap.ui": {
            "technology": "UI5",
            "deviceTypes": {
                "desktop": true,
                "tablet": true,
                "phone": true
            },
            "supportedThemes": [
                "sap_bluecrystal"
                ]
        },
        "sap.ui5": {

            "rootView": {
                  "viewName": "xxxxx.app.xxxxxx.POSView.App",
                  "type": "XML",
                  "async": true,
                  "id": "idAppControl"
              } ,
             "dependencies": {
                "minUI5Version": "1.30",
                "libs": {
                    "sap.m": {} ,
                    "sap.ui.core": {},
                    "sap.ui.layout": {}
                }
            },
            "models": {
                "i18n": {
                    "type": "sap.ui.model.resource.ResourceModel",
                    "settings": {
                        "bundleName": "xxxx.app.xxxxxx.i18n.messageBundle"
                    }
                },
                "oMainModel": {
                    "dataSource": "mainService",
                    "settings": {
                        "useBatch": false
                    }
                }
            } ,

            "routing" : {
                "config" : {
                "routerClass" : "xxxxxx.app.xxxxxx.MyRouter", 
                "viewType" : "XML",
                "viewPath" : "xxxxxx.app.xxxxxx.POSView",
                "controlId": "idAppControl",
                "targetAggregation" : "detailPages",
                "clearTarget" : "false"
            } ,

            "routes" : [
                {

                ]
        }
    }

}   

我认为您需要实现getRouter()方法,如下所示:

init : function() { 
..

..
}    
getRouter : function () {
    return sap.ui.core.UIComponent.getRouterFor(this);
}

我猜当前安装的SAP Ui5版本的coz是1.26,因此声明Manifest.json的新类型在这里不支持


重构回component.js中的元数据部分

检查
this.getRouter()的响应
this.getRouter()未定义感谢回复!但我已经在清单文件的routing->Config部分给出了路由器类的详细信息。因此,组件初始化后,清单将被初始化,因此我可以从组件访问配置。但我不能那样做!将UI5库升级到asap应该是组织中最优先考虑的事项之一。1.26是一个古老的版本,有几个安全问题,错过了性能优化机会。