routes - 无法初始化路由器
问题描述
我在尝试初始化 SAPUI5 的路由器时遇到问题。这是我的 webapp 文件夹结构: webapp 文件夹
在清单的底部,我定义了所有路由配置、路由和目标:
"routing": {
"config": {
"routerClass": "sap.m.routing.Router",
"viewType": "XML",
"viewPath": "ar.com.ordago.FSOT.view",
"controlId": "app",
"controlAggregation": "pages",
"transition": "slide",
"async": true
},
"routes": [{
"pattern": "",
"name": "appHome",
"target": "home"
}],
"targets": {
"home": {
"viewId": "home",
"viewName": "Home",
"viewLevel" : 1
}
}
我的 App.view:
<mvc:View
controllerName="ar.com.ordago.FSOT.controller.App"
xmlns:l="sap.ui.layout"
xmlns:mvc="sap.ui.core.mvc"
xmlns:core="sap.ui.core"
xmlns:form="sap.ui.layout.form"
xmlns="sap.m">
<App id="app"/>
</mvc:View>
我的家.view
<mvc:View
controllerName="ar.com.ordago.FSOT.controller.Home"
xmlns:l="sap.ui.layout"
xmlns:mvc="sap.ui.core.mvc"
xmlns:core="sap.ui.core"
xmlns="sap.m">
<pages>
<Page
id="page"
title="{i18n>title}">
<content>
</content>
</Page>
</Pages>
</mvc:View>
然后在 Component.js 我尝试创建路由器的实例(我包括它的所有开头以防万一):
sap.ui.define([
"sap/ui/core/UIComponent",
"sap/m/MessageToast",
"sap/ui/Device",
"sap/ui/model/json/JSONModel",
"./model/models",
"./model/formatter"
], function(UIComponent, MessageToast, Device, JSONModel, models) {
"use strict";
return UIComponent.extend("ar.com.ordago.FSOT.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);
// set the device model
this.setModel(models.createDeviceModel(), "device");
// create the views based on the url/hash
this.getRouter().initialize();
}
当我运行 webapp 时,出现以下错误:无法读取未定义的属性“初始化”
我在这里搜索,很多人都有类似的问题。但是对于建议的每个解决方案,问题是在 component.js 的 init 函数中没有 UIcomponent.prototype... 调用,但我确实有它,所以我不知道接下来要做什么来解决这个问题。
我在这里感谢您的帮助!
解决方案
解决了。
问题是 manifest.js 中使用的缩进已损坏。所有与路线和导航相关的信息都在节点“sap.ui5”的同一级别,当它们需要位于该节点的较低级别时。本质上,由于我混合了许多技术,因此我没有通过 SAP WebIDE 进行编码。但是为了解决这个问题,我在 WebIDE 中加载了项目,并且能够看到错误。我想在处理 SAPUI5 控件时最好通过 WebIDE 来维护它。
推荐阅读
- networking - 是否可以通过任意数量的节点生成胖树?
- python - 如何修改变量中的路径(python)?
- azure-cognitive-search - 支持政府社区云 (gcc) 中的 Azure 搜索服务
- java - 如何解压缩大量 gif
- python - 对带有配置文件的 python 日志记录感到困惑(仅记录在配置文件中为 root_logger 设置的内容)
- python - 为什么启用 Eager Execution 时可训练变量会消失?
- node.js - fluent-ffmpeg 与作物的纵横比
- c# - 使用泛型类型的问题
我的 C# 课 - c - GCC C 编译器(gcc -Wall -o foo.c foo.c)
- php - 如何从一串数据中获取小时和分钟?