【问题标题】:SAPUI5 routing - Control with ID idAppControl could not be foundSAPUI5 路由 - 找不到 ID 为 idAppControl 的控件
【发布时间】:2015-07-09 00:47:28
【问题描述】:

首先,我知道有类似的问题,但没有一个答案可以解决我的问题。

快速查看我的代码:

我的 Component.js 看起来像这样

routes: [
            {
                pattern: "",                //home page
                name: util.Constants.Tile,
                view: util.Constants.Tile,
                viewId: util.Constants.Tile,
                targetAggregation: "pages"
                //targetControl: "idAppControl"
            },
            {
                pattern: "firstExample",
                name: util.Constants.FirstExample,
                view: util.Constants.FirstExample,
                viewId: util.Constants.FirstExample,
                targetAggregation: "pages",
                targetControl : "idAppControl",
                subroutes : [
                    {
                        pattern: "firstExample",
                        name: util.Constants.ExampleMaster,
                        view: util.Constants.ExampleMaster,
                        targetAggregation: "masterPages",
                        targetControl: "idSplitContainerControl",
                    },
                    {
                        pattern: "firstExample/:typeMaster:",
                        name: util.Constants.ExampleSecondMaster,
                        view: util.Constants.ExampleSecondMaster,
                        targetAggregation: "masterPages",
                        targetControl: "idSplitContainerControl",
                        subroutes : [
                            {
                                pattern : "firstExample/:typeDetail:",
                                name : util.Constants.ExampleDetail,
                                view : util.Constants.ExampleDetail,
                                targetAggregation : "detailPages"
                            }
                        ]
                    }
                ]
            },

简短说明:这是一个具有普通应用视图(无主视图)的页面和一个具有两个主视图和一个详细视图的后续拆分容器。每当我想调用详细视图时

onSelect : function (e) {
    var routeTo = e.getSource().getTitle();

    this.router.navTo(util.Constants.ExampleDetail, { typeDetail : routeTo } );

},

它说

2015-03-30 14:50:06 找不到 ID 为 idAppControl 的控件 - sap-ui-core-dbg.js:15213

有什么想法吗? 提前感谢您的帮助!


类似主题的链接:

【问题讨论】:

  • targetControl 定义了将视图作为例如“内容”的聚合的控件。哪个控件应该满足您的意见?把这个控件的id放到targetControl: "id_of_your_control"
  • 感谢您的回答。我有一个 ID 为“idSplitContainerControl”的 SplitContainer (XML)。在 SplitApp 模式下,这个 ID 应该服务于我的观点。如果我用详细视图注释掉第二个子路由,它工作正常。我发现 DetailView(控制器和视图)甚至没有加载,即使它正确地路由到正确的 url。
  • 可能是因为您的子路由与主路由具有相同的模式。我认为对于普通路由器,由于贪婪选项,第二个模式将不匹配。但我不确定子路由的情况是否相同。您可以通过启用路由器中的贪婪选项来尝试它。 stackoverflow.com/questions/28948375/…
  • 其实不是同一个模式,我在“firstExample/”后面加上了被点击的列表元素的名字。我尝试了贪婪选项,发生的情况是路由器自动从第一个主视图跳转到第二个主视图,但仍然显示与之前相同的失败消息。再次感谢你的帮助! :)

标签: routing aggregation deep-linking sapui5


【解决方案1】:

很难调试别人的路由代码,所以这是我的多页应用程序的工作路由器。第一个是带有磁贴的简单页面,第二个是主/详细视图。

routes : [
    {
        pattern : "",
        name: "launchpad",
        view: "Launchpad",
        targetControl: "masterView"
    },
    {
        pattern : "split",
        name: "app",
        view: "App",
        targetControl: "masterView",
        subroutes : [
            {
                pattern : "master",
                name : "main",
                // placed in master masterPages aggregation of splitapp
                view : "Master",
                targetAggregation : "masterPages",
                targetControl : "idAppControl",
                // places detail in detailPages aggreg. of the splitapp
                subroutes : [
                    {
                        // product context is expected
                        // and which tab should be selected (supplier/category)
                        pattern : "{product}/:tab:",
                        name : "product",
                        view : "Detail",
                        targetAggregation :  "detailPages"
                    }
                ]
            }
        ]
    },
    // catchall routes, to show not found message, when route is not valid
    {
        name : "catchallMaster",
        view : "Master",
        targetAggregation : "masterPages",
        targetControl : "idAppControl",
        subroutes : [
            {
                pattern : ":all*:",
                name : "catchallDetail",
                view : "NotFound"
            }
        ]
    }
]
}
// custom routing is performed in MyRouter.js
},

请注意,两个路由都设置了 targetControl。 masterView 是首先加载的 MasterApp 的一部分。

<mvc:View
    xmlns:mvc="sap.ui.core.mvc"
    displayBlock="true"
    xmlns="sap.m">
    <App
        id="masterView">
    </App>
</mvc:View>

idAppControl 是带有&lt;SplitApp id="idAppControl" /&gt; 的App.view.xml 的一部分。我的应用程序和您一样基于开发人员指南中的示例。

Component.js 有这个:

createContent: function() {
    var viewData = {
        component:this
    };
    return sap.ui.view({
        viewName: "sap.ui.demo.app.view.MasterApp",
        type: sap.ui.core.mvc.ViewType.XML,
        viewData: viewData
    });
}

App.view:

<mvc:View
    xmlns:mvc="sap.ui.core.mvc"
    displayBlock="true"
    xmlns="sap.m">
    <SplitApp id="idAppControl" />
</mvc:View>

配置:

routing: {
    config: {
        // custom router class
        routerClass : sap.ui.demo.app.MyRouter,
        // xml views
        viewType : "XML",
        // absolute path to views
        viewPath : "sap.ui.demo.app.view",
        // unless stated otherwise, router places view in detail part
        targetAggregation : "pages",
        // don't clear the detail pages before views are added
        clearTarget : false
    },
}

查看您的路由器时,我会说您的页面顺序有问题。作为一般建议,我想说 navTo 采用路线的参数“名称”,而不是视图或模式。我花了一些时间来了解这一点。

亲切的问候,

迈克尔

【讨论】:

  • 感谢您的回答,抱歉回复晚了!我是否正确理解您使用普通的“应用程序视图”(名称:app)并在其上设置了一个 SplitContainer?以及如何调用第二个子路由中的详细视图?因为无论我有多少主视图,它们都可以正常工作,只有子路由中的详细视图会抛出错误消息。
  • 我从项目中删除了所有不必要的东西,并试图只保留非常基本的东西,也许这样可以更容易查看dl.dropboxusercontent.com/u/37336669/template%20new.zip这可能是一个非常简单和我犯了愚蠢的错误,但老实说我不明白!
  • 你不需要rootView: "view.App"`` in the Component.js when you have a createContent function in there. In the config you use targetAggregation : "detailPages"`,我在上面添加了我的配置。我不知道 UI5 对 targetAggregation 做了什么,这本身就是一个很奇怪的术语。但我的总是复数。 detailPages、masterPages、页面。我无法让您的应用程序运行,您使用的是 Node 还是它对您来说是独立的?
  • 哦,抱歉,我没有包含 sapui5 资源包,只是链接了托管在 netweaver.ondemand 上的 sap-ui-core.js,我认为这已经足够了......无论如何,我发现我的错误。你的配置是对的,我在其中包含了一个 targetControl,这导致了“无法找到 ID 为 idAppControl 的控件”错误。一个非常愚蠢且可以避免的错误!非常感谢你的帮助! :)
  • 我上传了。您可以在github.com/michaelklopf/ui5_launchpad_prototype 找到这些文件,但我没有再次对其进行测试,因此我不确定它是否适用于当前的 UI5 版本。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-18
  • 1970-01-01
  • 2016-11-19
  • 1970-01-01
  • 2017-10-31
  • 1970-01-01
相关资源
最近更新 更多