对于下面的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.Router的routeMatched事件。
API表示用于attachRoutePatternMatched()
将事件处理程序
fnFunction附加到此sap.ui.core.routing.Router的routePatternMatched事件。此事件类似于路由匹配。但是它只会对具有匹配模式的路由触发,而不会对其父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"
});
}
});
});没什么区别。不要理解,但它只会对具有匹配模式的路由触发,而不会对其父路径触发。
发布于 2017-09-17 17:45:41
这方面的不同之处是:
sap.ui.core.routing.Route和sap.ui.core.routing.Routersap.ui.core.routing.Route的attachMatched或attachPatternMatched用于特定指定的路由。在下面的路线详细说明:
let oRouter = sap.ui.core.UIComponent.getRouterFor(this);
oRouter.getRoute("detail").attachMatched(this._onObjectMatched, this); sap.ui.core.routing.Router's attachRouteMatched或attachRoutePatternMatched在任何路线上都会起火:
let oRouter = sap.ui.core.UIComponent.getRouterFor(this);
oRouter.attachRouteMatched(this._onObjectMatched, this);为了澄清这一点:如果对某一特定路线添加了限制,sap.ui.core.routing.Router的方法将与sap.ui.core.routing.Route的方法相同:
_onObjectMatched: function(oEvent) {
if (oEvent.getParameter("name") !== "detail") {
…
}
}但无论如何,sap.ui.core.routing.Router对任何路线都会使用_onObjectMatched。对详细路由的限制发生在带有if子句的激发方法_onObjectMatched中。sap.ui.core.routing.Route只在detail路由被击中时才首先触发_onObjectMatched。
sap.ui.core.routing.Router的attachMatched/sap.ui.core.routing.Route的attachRouteMatched和sap.ui.core.routing.Router的attachPatternMatched/sap.ui.core.routing.Route的attachRoutePatternMatchedattachMatched/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用于子路由或父路由,而不是父路由。https://stackoverflow.com/questions/43706819
复制相似问题