SAPUI5 路由:无法读取未定义的 属性 'initialize'
SAPUI5 Routing: Cannot read property 'initialize' of undefined
我在创建路由器时遇到问题。我每次都会收到错误 Cannot read property 'initialize' of undefined
。
这是我的代码 Component.js:
sap.ui.define([ "sap/ui/core/UIComponent", "sap/ui/model/json/JSONModel",
"sap/ui/core/routing/History", "sap/m/routing/RouteMatchedHandler" ],
function(UIComponent, JSONModel, Router, RouteHandler) {
"use strict";
return UIComponent.extend("myApp.Component", {
metadata: {
routing:{
config: {
viewType:"XML",
viewPath:"myApp.view",
targetControl: "idRoot",
targetAggregation: "pages",
clearTarget: false
},
routes:[{
pattern: "",
name:"Master",
view:"Master"
}]
}
},
init: function(){
var router = this.getRouter(); //Doesn't work
router.initialize(); //ERROR HERE
},
如果我尝试 var router = sap.ui.core.routing.Router.getRouter();
是一样的。
谁能帮我解决这个问题?
您缺少这行代码:
UIComponent.prototype.init.apply(this, arguments);
初始化路由器前需要先调用parent的init函数
我在创建路由器时遇到问题。我每次都会收到错误 Cannot read property 'initialize' of undefined
。
这是我的代码 Component.js:
sap.ui.define([ "sap/ui/core/UIComponent", "sap/ui/model/json/JSONModel",
"sap/ui/core/routing/History", "sap/m/routing/RouteMatchedHandler" ],
function(UIComponent, JSONModel, Router, RouteHandler) {
"use strict";
return UIComponent.extend("myApp.Component", {
metadata: {
routing:{
config: {
viewType:"XML",
viewPath:"myApp.view",
targetControl: "idRoot",
targetAggregation: "pages",
clearTarget: false
},
routes:[{
pattern: "",
name:"Master",
view:"Master"
}]
}
},
init: function(){
var router = this.getRouter(); //Doesn't work
router.initialize(); //ERROR HERE
},
如果我尝试 var router = sap.ui.core.routing.Router.getRouter();
是一样的。
谁能帮我解决这个问题?
您缺少这行代码:
UIComponent.prototype.init.apply(this, arguments);
初始化路由器前需要先调用parent的init函数