如何引发的Backbone.js的事件Backbone.Router? [英] How to trigger the Backbone.Router events in Backbone.js?
问题描述
路由器在Backbone.js的负责路由客户端的网页,并把它们连接到的行动,并根据网址事件。但如何触发URL变化?我的意思是,如果做到这一点的唯一方法就是包围与页面路由在&LT关联的元素; A>
标记。
Router in Backbone.js is responsible for routing client-side pages, and connecting them to actions and events based on urls. But how to trigger the url change? I mean if the only way to do this is to enclose the element associated with page routing in <a>
tag.
由于我有关联的鼠标按下和MouseUp事件与用于路由的元素,如果我把它放在&LT; A&GT;
标签,鼠标按下和MouseUp事件肯定会无效,因为它会与&LT的单击事件冲突; A&GT;
标记。那么,有没有其他的方法来使路由?
Because I have associated the mousedown and mouseup events with the element used for routing, if I put it in <a>
tag, the mousedown and mouseup events will definitely become invalid as it will have conflict with the click event of <a>
tag. So is there other ways to make the routing?
推荐答案
您可以使用 路由器#导航
:
You can use Router#navigate
:
导航 router.navigate(片段[选项])
每当你达到你的应用程序的一个点,你想保存为一个URL,调用的浏览,以更新URL。如果你想又拨打了路由功能,将触发选项为真正
。
Whenever you reach a point in your application that you'd like to save as a URL, call navigate in order to update the URL. If you wish to also call the route function, set the trigger option to true
.
所以,如果你的路由器是研究
并要激活路线#/ some_route
,那么你可以:
So, if your router is r
and you want to activate the route for #/some_route
, then you could:
r.navigate('some_route', { trigger: true });
示范(打开控制台请): http://jsfiddle.net/ambiguous/xkZtB/
这篇关于如何引发的Backbone.js的事件Backbone.Router?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!