我有一个控制器:
Menu.Controller.js:
sap.ui.define([
"sapit/ext/utils/BaseController",
"sap/ui/model/json/JSONModel",
"sap/ui/model/Sorter",
"sap/ui/model/Filter",
"sapit/nova/model/constants",
"sapit/ nova /model/formatter",
"sapit/ nova /util/Helper",
"sapit/ nova /util/Validator",
"sapit/ nova /util/ItemService"
], function(BaseController, JSONModel, Sorter, Filter, constants, formatter, Helper, Validator, ItemService) {
"use strict";
return BaseController.extend("sapit.nova.controller.Menu", {
formatter: formatter,
helper: new Helper(),
itemService: new ItemService(),
onInit: function() {
this.fragmentProcess = sap.ui.xmlfragment("sapit.nova.view.fragment.Process", this);
// attach events
this.getRouter().attachRouteMatched(jQuery.proxy(this.onRouteMatched, this));
},
onRouteMatched: function(oEvent) {
var oPage = this.byId("menuProcessor");
var sRouteName = oEvent.getParameter("name");
if (sRouteName === "Menu") {
// show fragment
this.helper.clearFragment(oPage);
this.helper.showFragment(oPage, this.fragmentProcess);
}
我有相应的xml视图,如Menu.view.xml:
mvc:View controllerName="sapit.nova.controller.Menu" xmlns="sap.m" xmlns:mvc="sap.ui.core.mvc">
<Page id="menuProcessor" title="{i18n>menuPageTitle}" showNavButton="false">
</Page>
</mvc:View>
我的路由器配置是:
"routes": [{
"pattern": "/admin",
"name": "Main",
"target": ["menu"]
},
"targets": {
"menu": {
"viewName": "Menu",
"viewLevel": 1,
"controlAggregation": "masterPages"
}
问题是,当我运行此应用程序控件时,将转到menu.controller的onInit(),但它不会转到onRouteMatched,尽管它正在将路由器的实例附加到此视图。
每次运行此应用程序时,我都会在输入onInit()后收到错误,其余代码不起作用且视图不会出现。
Uncaught (in promise) Error: Cannot instantiate object: "new" is missing!
at constructor (sap-ui-core.js:640)
at constructor (sap-ui-core.js:1601)
at constructor (sap-ui-core.js:1571)
at f (sap-ui-core.js:638)
at f (sap-ui-core.js:284)
at p (sap-ui-core.js:285)
at _ (sap-ui-core.js:286)
at Object.properties (sap-ui-core.js:286)
at l (sap-ui-core.js:298)
at B.getText (sap-ui-core.js:296)
在这方面,请你建议我。
谢谢!
答案 0 :(得分:0)
从sap.ui.define中删除空格,这在加载Helper,Validator和ItemService时可能会出现问题
sap.ui.define([
"sapit/ext/utils/BaseController",
"sap/ui/model/json/JSONModel",
"sap/ui/model/Sorter",
"sap/ui/model/Filter",
"sapit/nova/model/constants",
"sapit/ nova /model/formatter",
"sapit/ nova /util/Helper",
"sapit/ nova /util/Validator",
"sapit/ nova /util/ItemService"
],
答案 1 :(得分:0)
您没有实例化您的片段。
试试这个:
this.fragmentProcess = new sap.ui.xmlfragment("sapit.nova.view.fragment.Process", this);