gpt4 book ai didi

sapui5 - SAPUI5 中的 attachMatched() 和 attachPatternMatched() 和/或 attachRouteMatched() 和 attachRoutePatternMatched() 有什么区别?

转载 作者:行者123 更新时间:2023-12-04 14:55:23 24 4
gpt4 key购买 nike

对于以下 SAPUI5 路由方法之间的区别的示例,我们会很高兴:

sap.ui.core.routing.Route :

  • attachMatched()
  • attachPatternMatched()

  • sap.ui.core.routing.Router :
  • attachRouteMatched()
  • attachRoutePatternMatched()

  • API 表示为 attachMatched()attachPatternMatched()没有任何区别。

    API 表示为 attachRouteMatched() :

    Attach event-handler fnFunction to the routeMatched event of this sap.ui.core.routing.Router.



    API 表示为 attachRoutePatternMatched() :

    Attach event-handler fnFunction to the routePatternMatched event of this sap.ui.core.routing.Router. This event is similar to route matched. But it will only fire for the route that has a matching pattern, not for its parent Routes.



    例如。可以用

    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"
    });
    }
    });
    });

    或者

    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"
    });
    }
    });
    });

    看不出区别。不要得到“但它只会为具有匹配模式的路由触发,而不是为其父路由触发。”思想 attachRouteMatch()只会为具有匹配模式的路由触发。

    最佳答案

    在这种情况下的差异是:

  • sap.ui.core.routing.Routesap.ui.core.routing.Router
  • sap.ui.core.routing.RouteattachMatchedattachPatternMatched为特定的规定路线开火。在下面的路线«细节»:

    let oRouter = sap.ui.core.UIComponent.getRouterFor(this);
    oRouter.getRoute("detail").attachMatched(this._onObjectMatched, this);
    sap.ui.core.routing.RouterattachRouteMatchedattachRoutePatternMatched任何路线的火灾:

    let oRouter = sap.ui.core.UIComponent.getRouterFor(this);            
    oRouter.attachRouteMatched(this._onObjectMatched, this);

    为了澄清起见: sap.ui.core.routing.Router的方法将具有与 sap.ui.core.routing.Route 相同的结果's 如果为特定路由添加了限制:

    _onObjectMatched: function(oEvent) {
    if (oEvent.getParameter("name") !== "detail") {

    }
    }

    尽管如此, sap.ui.core.routing.Router火灾 _onObjectMatched对于任何路线。对详细路由的限制发生在触发方法 _onObjectMatched 中与 if 子句。 sap.ui.core.routing.Route火灾 _onObjectMatched首先只有当 «detail» 路由被点击时。
  • 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;博士:
  • 具体路线与sap.ui.core.routing.Route .
  • 没有与 sap.ui.core.routing.Router 的具体路线.
  • attachMatched/attachRouteMatched任何路线的火灾。
  • attachPatternMatched/attachRoutePatternMatched为子路由触发,或者不为父路由触发。
  • 关于sapui5 - SAPUI5 中的 attachMatched() 和 attachPatternMatched() 和/或 attachRouteMatched() 和 attachRoutePatternMatched() 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43706819/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com