对于以下SAPUI5路由方法之间的区别有一个示例感到高兴:
sap.ui.core.routing.Route:
attachMatched()attachPatternMatched()sap.ui.core.routing.Router:
attachRouteMatched()attachRoutePatternMatched()API说明了什么attachMatched(),attachPatternMatched()没有任何区别。
API表示attachRouteMatched():
将event-handler附加
fnFunction到routeMatchedthis 的事件上sap.ui.core.routing.Router。
API表示attachRoutePatternMatched():
将event-handler附加
fnFunction到routePatternMatchedthis 的事件上sap.ui.core.routing.Router。此事件类似于路由匹配。但它只会对具有匹配模式的路由触发,而不会针对其父模式触发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"
});
}
});
});
Run Code Online (Sandbox Code Playgroud)
要么
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"
});
}
});
});
Run Code Online (Sandbox Code Playgroud)
没什么区别。不要得到«但只会为具有匹配模式的路由触发,而不会为其父路由attachRouteMatch()触发。”思想只会为具有匹配模式的路由触发。
在这方面的区别是:
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);
Run Code Online (Sandbox Code Playgroud)
sap.ui.core.routing.Router的attachRouteMatched或attachRoutePatternMatched任何航线火灾:
let oRouter = sap.ui.core.UIComponent.getRouterFor(this);
oRouter.attachRouteMatched(this._onObjectMatched, this);
Run Code Online (Sandbox Code Playgroud)
为了澄清起见:如果为特定路线添加了限制,则sap.ui.core.routing.Router的方法将具有与相同的结果sap.ui.core.routing.Route:
_onObjectMatched: function(oEvent) {
if (oEvent.getParameter("name") !== "detail") {
…
}
}
Run Code Online (Sandbox Code Playgroud)
但是,无论如何,都会sap.ui.core.routing.Router开火_onObjectMatched。对详细路由的限制发生在_onObjectMatched带有if子句的fired方法中。仅在按下“详细”路线时才sap.ui.core.routing.Route触发_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触发子路由,而不触发父路由。| 归档时间: |
|
| 查看次数: |
4840 次 |
| 最近记录: |