温馨提示:本文翻译自stackoverflow.com,查看原文请点击:其他 - SAPUI5 routing errors Control with ID app could not be found
routing sapui5

其他 - SAPUI5路由错误找不到具有ID应用程序的控件

发布于 2020-04-16 13:22:57

我知道这是个比较简单的问题,但是没有答案可以解决我的问题。我想通过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");
    }
});

});

我尽一切努力,谷歌能够向我展示。我现在真的很困惑。而且我还尝试删除“ sap.ui5”中的“ rootview”-不起作用。任何帮助都将受到欢迎!提前致谢!

查看更多

提问者
mkbb
被浏览
190
Voyager 2020-01-08 22:14

我想主视图是您的根视图?发生错误是因为您在主视图中的应用没有ID,它应使用ID“ app”,因为此ID在清单中定义为controlId。这样,路由器可以找到它并将其用作导航容器。