首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >attachMatched()和attachPatternMatched()和/或attachRouteMatched()和attachRoutePatternMatched()在SAPUI5中有什么区别?

attachMatched()和attachPatternMatched()和/或attachRouteMatched()和attachRoutePatternMatched()在SAPUI5中有什么区别?
EN

Stack Overflow用户
提问于 2017-04-30 13:17:36
回答 1查看 11.7K关注 0票数 8

对于下面的SAPUI5路由方法之间有什么不同的例子,我会很高兴的:

sap.ui.core.routing.Route

  • attachMatched()
  • attachPatternMatched()

sap.ui.core.routing.Router

  • attachRouteMatched()
  • attachRoutePatternMatched()

API对attachMatched()attachPatternMatched()没有任何区别。

API表示用于attachRouteMatched()

将事件处理程序fnFunction附加到此sap.ui.core.routing.RouterrouteMatched事件。

API表示用于attachRoutePatternMatched()

将事件处理程序fnFunction附加到此sap.ui.core.routing.RouterroutePatternMatched事件。此事件类似于路由匹配。但是它只会对具有匹配模式的路由触发,而不会对其父Routes触发。

例如可以使用

代码语言:javascript
复制
sap.ui.define([
    "sap/ui/core/mvc/Controller"
], function (Controller) {
    "use strict";
    return Controller.extend("sap.ui.demo.wt.controller.Detail", {
        onInit: function () {
            var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
            oRouter.getRoute("detail").attachMatched(this._onObjectMatched, this);              
            // oRouter.attachRouteMatched(this._onObjectMatched, this);
        },
        _onObjectMatched: function (oEvent) {
            this.getView().bindElement({
                path: "/" + oEvent.getParameter("arguments").invoicePath,
                model: "invoice"
            });
        }
    });
});

代码语言:javascript
复制
sap.ui.define([
    "sap/ui/core/mvc/Controller"
], function (Controller) {
    "use strict";
    return Controller.extend("sap.ui.demo.wt.controller.Detail", {
        onInit: function () {
            var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
            oRouter.getRoute("detail").attachPatternMatched(this._onObjectMatched, this);
            // oRouter.attachRoutePatternMatched(this._onObjectMatched, this);
        },
        _onObjectMatched: function (oEvent) {
            this.getView().bindElement({
                path: "/" + oEvent.getParameter("arguments").invoicePath,
                model: "invoice"
            });
        }
    });
});

没什么区别。不要理解,但它只会对具有匹配模式的路由触发,而不会对其父路径触发。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-09-17 17:45:41

这方面的不同之处是:

  1. sap.ui.core.routing.Routesap.ui.core.routing.Router

sap.ui.core.routing.RouteattachMatchedattachPatternMatched用于特定指定的路由。在下面的路线详细说明:

代码语言:javascript
复制
let oRouter = sap.ui.core.UIComponent.getRouterFor(this);
oRouter.getRoute("detail").attachMatched(this._onObjectMatched, this);   

sap.ui.core.routing.Router's attachRouteMatchedattachRoutePatternMatched在任何路线上都会起火:

代码语言:javascript
复制
let oRouter = sap.ui.core.UIComponent.getRouterFor(this);            
oRouter.attachRouteMatched(this._onObjectMatched, this);

为了澄清这一点:如果对某一特定路线添加了限制,sap.ui.core.routing.Router的方法将与sap.ui.core.routing.Route的方法相同:

代码语言:javascript
复制
_onObjectMatched: function(oEvent) {
    if (oEvent.getParameter("name") !== "detail") {
        …
    }
}

但无论如何,sap.ui.core.routing.Router对任何路线都会使用_onObjectMatched。对详细路由的限制发生在带有if子句的激发方法_onObjectMatched中。sap.ui.core.routing.Route只在detail路由被击中时才首先触发_onObjectMatched

  1. sap.ui.core.routing.RouterattachMatched/sap.ui.core.routing.RouteattachRouteMatchedsap.ui.core.routing.RouterattachPatternMatched/sap.ui.core.routing.RouteattachRoutePatternMatched

attachMatched/attachRouteMatched激发匹配的路由attachMatched为任何路由或子路由触发。attachRouteMatched为指定路由的匹配触发。

给出结论:

  • attachPatternMatched/attachRoutePatternMatched为匹配的子路由触发。
  • attachPatternMatched为路由的子路线点火。
  • attachRoutePatternMatched为任何匹配的子路由触发。也就是说,attachPatternMatched/attachRoutePatternMatched对没有母路由的情况下会发生火灾。

tl;dr:

  • sap.ui.core.routing.Route的具体路线。
  • 没有与sap.ui.core.routing.Router的具体路线。
  • attachMatched/attachRouteMatched为任何路线开火。
  • attachPatternMatched/attachRoutePatternMatched用于子路由或父路由,而不是父路由。
票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43706819

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档