无法找到带有 ID 应用程序的 SAPUI5 路由错误控件
SAPUI5 routing errors Control with ID app could not be found
我知道有些问题很滑稽,但没有一个答案可以解决我的问题。
我想通过 btn 单击从一个页面导航到另一个页面。
当我按下一个按钮时,控制台中出现一个错误:
Target-dbg.js:386 Uncaught (in promise) Error: Control with ID app could not be found - Target: TargetReportsView
at constructor._refuseInvalidTarget (Target-dbg.js:386)
at Target-dbg.js:262
这是我的路由清单:
"routing": {
"config": {
"routerClass": "sap.m.routing.Router",
"viewType": "XML",
"async": true,
"viewPath": "CompName.Emp_ITDB.Emp_ITDB.view",
"controlAggregation": "pages",
"controlId": "app",
"clearControlAggregation": false
},
"routes": [{
"name": "RouteMainView",
"pattern": "RouteMainView",
"target": ["TargetMainView"]
}, {
"name": "TargetReportsView",
"pattern": "TargetReportsView",
"greedy": false,
"target": ["TargetReportsView"]
}],
"targets": {
"TargetMainView": {
"viewType": "XML",
"transition": "slide",
"clearControlAggregation": false,
"viewId": "MainView",
"viewName": "MainView"
},
"TargetReportsView": {
"viewType": "XML",
"viewName": "ReportsView",
"viewId": "ReportsView"
}
}
}
以及我的观点:
- 主要
<mvc:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:smartFilterBar="sap.ui.comp.smartfilterbar" xmlns:smartTable="sap.ui.comp.smarttable" controllerName="CompName.Emp_ITDB.Emp_ITDB.controller.MainView">
<App>
<pages><Page title="EmployeeDB">
<content>
<Toolbar width="100%" id="toolbar1" design="Transparent">
<content>
<Button xmlns="sap.m" text="{i18n>databaseBar}" id="databaseBarBtn"/>
<Button xmlns="sap.m" text="{i18n>reportsBar}" id="reportsBarBtn" press="NavigateToReports"/>
<Button xmlns="sap.m" text="{i18n>adminBar}" id="adminBarBtn"/>
</content>
</Toolbar>
</content>
</Page>
</pages>
</App>
和 - 报告
<mvc:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m"
controllerName="CompName.Emp_ITDB.Emp_ITDB.controller.ReportsView" xmlns:html="http://www.w3.org/1999/xhtml">
<App id="TargetReportsView">
<pages>
<Page title="Title">
<content></content>
</Page>
</pages>
</App>
最后但同样重要的是我的控制者:
sap.ui.define(["sap/ui/core/mvc/Controller"], function (Controller) {
"use strict";
return Controller.extend("CompName.Emp_ITDB.Emp_ITDB.controller.MainView", {
/**
* Called when a controller is instantiated and its View controls (if available) are already created.
* Can be used to modify the View before it is displayed, to bind event handlers and do other one-time initialization.
* @memberOf CompName.Emp_ITDB.Emp_ITDB.view.MainView
*/
getRouter : function () {
return sap.ui.core.UIComponent.getRouterFor(this);
},
onInit: function () {},
/**
*@memberOf CompName.Emp_ITDB.Emp_ITDB.controller.MainView
*/
ClearSearchBtnPressed: function (oEvent) {
this.byId("employeeSearchBar").setValue("");
},
/**
*@memberOf CompName.Emp_ITDB.Emp_ITDB.controller.MainView
*/
NavigateToReports: function (oEvent) {
this.getOwnerComponent().getRouter().getTargets().display("TargetReportsView");
}
});
});
我尝试了 google 能够告诉我的一切。
我现在真的很困惑。
我还尝试在 "sap.ui5" 中删除 "rootview" - 不起作用。
欢迎任何帮助!提前致谢!
我猜主视图是您的根视图?出现这个错误是因为你的主视图中的App没有id,它应该使用id "app" 因为这个id在manifest中被定义为controlId。这样路由器就可以找到并用作导航容器。
<App id="app"> </App>
尝试这样做,这可能会有所帮助。
我知道有些问题很滑稽,但没有一个答案可以解决我的问题。 我想通过 btn 单击从一个页面导航到另一个页面。 当我按下一个按钮时,控制台中出现一个错误:
Target-dbg.js:386 Uncaught (in promise) Error: Control with ID app could not be found - Target: TargetReportsView
at constructor._refuseInvalidTarget (Target-dbg.js:386)
at Target-dbg.js:262
这是我的路由清单:
"routing": {
"config": {
"routerClass": "sap.m.routing.Router",
"viewType": "XML",
"async": true,
"viewPath": "CompName.Emp_ITDB.Emp_ITDB.view",
"controlAggregation": "pages",
"controlId": "app",
"clearControlAggregation": false
},
"routes": [{
"name": "RouteMainView",
"pattern": "RouteMainView",
"target": ["TargetMainView"]
}, {
"name": "TargetReportsView",
"pattern": "TargetReportsView",
"greedy": false,
"target": ["TargetReportsView"]
}],
"targets": {
"TargetMainView": {
"viewType": "XML",
"transition": "slide",
"clearControlAggregation": false,
"viewId": "MainView",
"viewName": "MainView"
},
"TargetReportsView": {
"viewType": "XML",
"viewName": "ReportsView",
"viewId": "ReportsView"
}
}
}
以及我的观点: - 主要
<mvc:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:smartFilterBar="sap.ui.comp.smartfilterbar" xmlns:smartTable="sap.ui.comp.smarttable" controllerName="CompName.Emp_ITDB.Emp_ITDB.controller.MainView">
<App>
<pages><Page title="EmployeeDB">
<content>
<Toolbar width="100%" id="toolbar1" design="Transparent">
<content>
<Button xmlns="sap.m" text="{i18n>databaseBar}" id="databaseBarBtn"/>
<Button xmlns="sap.m" text="{i18n>reportsBar}" id="reportsBarBtn" press="NavigateToReports"/>
<Button xmlns="sap.m" text="{i18n>adminBar}" id="adminBarBtn"/>
</content>
</Toolbar>
</content>
</Page>
</pages>
</App>
和 - 报告
<mvc:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m"
controllerName="CompName.Emp_ITDB.Emp_ITDB.controller.ReportsView" xmlns:html="http://www.w3.org/1999/xhtml">
<App id="TargetReportsView">
<pages>
<Page title="Title">
<content></content>
</Page>
</pages>
</App>
最后但同样重要的是我的控制者:
sap.ui.define(["sap/ui/core/mvc/Controller"], function (Controller) {
"use strict";
return Controller.extend("CompName.Emp_ITDB.Emp_ITDB.controller.MainView", {
/**
* Called when a controller is instantiated and its View controls (if available) are already created.
* Can be used to modify the View before it is displayed, to bind event handlers and do other one-time initialization.
* @memberOf CompName.Emp_ITDB.Emp_ITDB.view.MainView
*/
getRouter : function () {
return sap.ui.core.UIComponent.getRouterFor(this);
},
onInit: function () {},
/**
*@memberOf CompName.Emp_ITDB.Emp_ITDB.controller.MainView
*/
ClearSearchBtnPressed: function (oEvent) {
this.byId("employeeSearchBar").setValue("");
},
/**
*@memberOf CompName.Emp_ITDB.Emp_ITDB.controller.MainView
*/
NavigateToReports: function (oEvent) {
this.getOwnerComponent().getRouter().getTargets().display("TargetReportsView");
}
});
});
我尝试了 google 能够告诉我的一切。 我现在真的很困惑。 我还尝试在 "sap.ui5" 中删除 "rootview" - 不起作用。 欢迎任何帮助!提前致谢!
我猜主视图是您的根视图?出现这个错误是因为你的主视图中的App没有id,它应该使用id "app" 因为这个id在manifest中被定义为controlId。这样路由器就可以找到并用作导航容器。
<App id="app"> </App>
尝试这样做,这可能会有所帮助。