【问题标题】:SAPUI5 routing errors Control with ID app could not be foundSAPUI5 路由错误 找不到带有 ID 应用程序的控件
【发布时间】:2020-02-04 12:56:53
【问题描述】:

我知道有一些类似的问题,但没有一个答案可以解决我的问题。 我想用 btn click 从一个页面导航到另一个页面。 当我按下按钮时,控制台中有一个错误:

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” - 不起作用。 欢迎任何帮助!提前致谢!

【问题讨论】:

    标签: routing sapui5


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:
      <App id="app"> </App>
      

      尝试这样做,这可能会有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-05-18
        • 2023-03-07
        • 1970-01-01
        • 1970-01-01
        • 2017-12-09
        • 2021-09-09
        相关资源
        最近更新 更多