我的应用程序中的所有视图都被加载了两次。当我检查网络选项卡时,我看到视图被加载了两次,而控制器也加载了一次。当我尝试导航到其他视图时,控制台出现错误。 我认为我的路由器配置中可能有问题。
Component.js文件:
sap.ui.define([
"sap/ui/core/UIComponent",
"sap/ui/Device",
"UI5_Module/resources/webapp/model/models"
], function(UIComponent, Device, models) {
"use strict";
return UIComponent.extend("UI5_Module.resources.webapp.Component", {
metadata: {
manifest: "json"
},
init: function() {
// call the base component's init function
UIComponent.prototype.init.apply(this, arguments);
this.getRouter().initialize();
}
});
});
index.html文件:
<script id="sap-ui-bootstrap"
src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"
data-sap-ui-libs="sap.m,sap.viz"
data-sap-ui-theme="sap_bluecrystal"
data-sap-ui-xx-bindingSyntax="complex"
data-sap-ui-preload="async"
data-sap-ui-language="en"
data-sap-ui-resourceroots='{"UI5_Module.resources.webapp": "../"}'>
</script>
<!--<link rel="stylesheet" href="../css/style.css">-->
<script>
sap.ui.getCore().attachInit(function() {
sap.ui.component({
name:"UI5_Module.resources.webapp",
// async:true,
manifest:true
}).then(function(oComponent) {
sap.ui.require([
"UI5_Module/resources/webapp/localService/mockserver",
"sap/m/Shell",
"sap/ui/core/ComponentContainer"
], function (mockserver, Shell, ComponentContainer) {
new Shell({
app: new sap.ui.core.ComponentContainer({
height : "100%",
name : "UI5_Module.resources.webapp"
})
}).placeAt("content");
});
});
});
</script>
Manifest.json文件:
{
"_version": "1.5.0",
"sap.app": {
"id": "UI5_Module",
"type": "application",
"i18n": "i18n/i18n.properties",
"applicationVersion": {
"version": "1.0.0"
},
"title": "{{appTitle}}",
"description": "{{appDescription}}",
"resources": "resources.json",
"ach": "ach",
"sourceTemplate": {
"id": "hanatemplates.basicSAPUI5ApplicationProject",
"version": "0.0.0"
}
},
"sap.ui": {
"technology": "UI5",
"icons": {
"icon": "",
"favIcon": "",
"phone": "",
"phone@2": "",
"tablet": "",
"tablet@2": ""
},
"deviceTypes": {
"desktop": true,
"tablet": true,
"phone": true
},
"supportedThemes": [
"sap_hcb",
"sap_bluecrystal"
]
},
"sap.ui5": {
"rootView": {
"viewName": "UI5_Module.resources.webapp.view.RootView",
"type": "XML"
},
"dependencies": {
"minUI5Version": "1.30.0",
"libs": {
"sap.ui.core": {},
"sap.m": {}
}
},
"contentDensities": {
"compact": true,
"cozy": true
},
"models": {
"i18n": {
"type": "sap.ui.model.resource.ResourceModel",
"settings": {
"bundleName": "UI5_Module.resources.webapp.i18n.i18n"
}
}
},
"resources": {
"css": [{
"uri": "css/style.css"
}]
},
"routing": {
"config": {
"routerClass": "sap.m.routing.Router",
"viewType": "XML",
"viewPath": "UI5_Module.resources.webapp.view",
"controlId": "RootApp",
"controlAggregation": "pages",
"transition": "slide",
"clearTarget": true,
"async": true
},
"routes": [{
"pattern": "",
"name": "default",
"target": "Main"
}, {
"pattern": "List/",
"name": "List",
"target": "List"
}, {
"pattern": "Details/",
"name": "Details",
"target": "Details"
}]}
RootView文件:
<mvc:View controllerName="UI5_Module.resources.webapp.controller.RootView"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:mvc="sap.ui.core.mvc"
displayBlock="true" xmlns="sap.m">
<App id="RootApp">
</App>
</mvc:View>
答案 0 :(得分:0)
我认为,这是您在加载组件的第一个块中index.html =>中的attachInit块,但是您从未在then
部分中使用它。
相反,ComponentContainer
中的new Shell
将第二次加载您的组件。