本文介绍了sap.ui.core.routing.Router.navTo() 和 sap.m.routing.Targets.display() 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们有一条路线和一个目标:

Let’s say we I have one route and one target:

"routes": [{
  "pattern": "modify",
  "name": "modify",
  "target": [
    "master",
    "modify"
  ]
}],
"targets": {
  "modify": {
    "viewName": "Modify",
    "viewId": "modify",
    "viewLevel": 2
  }
}

所以我可以通过this.getRouter().navTo("modify")访问路由,同时我可以通过this.getRouter().getTargets()访问目标.显示(修改").两个 API 都可以通过第二个参数携带参数.似乎达到了同样的效果.

So I can access the route by this.getRouter().navTo("modify"), meanwhile I can access the target by this.getRouter().getTargets().display("modify"). Both API can carry parameter by the second argument. It seems to achieve the same effect.

我可以访问目标而无需为其定义路由.所以我不太明白为什么我需要一条路线?

I can access target without defining a route for it. So I did not quite understand why I need a route?

参考:sap.m.routing.Targetssap.ui.core.routing.Router

推荐答案

displaydisplay 相比,在不改变哈希值的情况下显示目标视图a href="https://github.com/SAP/openui5/blob/rel-1.48.5/src/sap.ui.core/src/sap/ui/core/routing/Router.js#L522" rel="nofollow noreferrer">navTo.

您可以在教程显示目标而不更改哈希".

两个 API 都可以通过第二个参数携带参数.似乎达到了同样的效果.

  • display method 中的 data 用于 display event 处理程序.当事件是 触发,处理程序携带我们之前传递的数据.
  • 我们可以传递给navTo参数映射强制性的,如果模式实际上等待一个参数,例如如果我们最初定义了这样的模式:"pattern": "modify/{id}".查看导航到带有强制参数的路由".
    • The data in display method is for the display event handler. When the event is fired, the handler carries the data we passed earlier.
    • The parameter map we can pass to navTo is mandatory if the pattern actually awaits a parameter, e.g. if we've defined the pattern like this initially: "pattern": "modify/{id}". Check out "Navigate to Routes with Mandatory Parameters".
    • 这篇关于sap.ui.core.routing.Router.navTo() 和 sap.m.routing.Targets.display() 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 01:32