程序化“返回”在 Backbone.js 中
我有一个 #/xxx
中的项目列表,单击该列表时会弹出一个灯箱并将哈希更改为 #/xxx/yyy
。在灯箱中,有一个“后退”按钮。如何恢复到上一页(即“#/xxx
”)?我正在寻找类似“Backbone.back()
”的内容。此操作不得触发路由处理程序(否则项目列表将为空,因为它是 Ajax 搜索结果)。
I have a list of items in #/xxx
which when clicked will pop up a lightbox and change the hash to #/xxx/yyy
. In the lightbox, there's a "Back" button. How do I revert to previous page (i.e. "#/xxx
")? I'm looking for something like "Backbone.back()
". This action must not trigger the route handler (otherwise the list of items will be empty since it's an Ajax search result).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我可以想到两种简单的方法来做到这一点:
1)使“后退”按钮根本不返回,只需再次重复上一条路线(调出灯箱之前的路线)即可。然后回顾历史就会产生你期望看到的结果。
2) 只需告诉浏览器在历史记录中后退一步即可。您可以在 JavaScript 中执行此操作,如下所示:
结果应该与执行同一操作的其他方法一样。
There's two easy ways I can think of doing this:
1) Make the "back" button not really go back at all, just repeat the previous route (the one prior to bringing up the lightbox) again. Then going backwards and forwards through the history will produce the results you expect to see.
2) Just tell the browser to step back one step within the history. You can do that in JavaScript like so:
Results should be just like the other way of doing the same thing.