Backbone.Router.navigate()之后运行函数

时间:2012-06-27 03:04:10

标签: backbone.js coffeescript

我想在backbone.navigate调用之后运行一个函数(以呈现flash消息)。可能吗?我目前挂钩了all事件并检查eventname是否以“route:”开头。但是在我的消息被添加之前触发得太早......所以我想在路线完成后继续运行

# intercept all router navigate and render flash messages if any
renderFlashMessengesOnNavigate = (evt) =>
  if evt.indexOf("route:") is 0 
    console.log "rendering messages after route ..."
    @flashMessenger.render()
window.appRouter.bind "all", renderFlashMessengesOnNavigate
window.authRouter.bind "all", renderFlashMessengesOnNavigate
window.userRouter.bind "all", renderFlashMessengesOnNavigate

1 个答案:

答案 0 :(得分:7)

试试这个:

var originalNavigate = Backbone.history.navigate;
Backbone.history.navigate = function(fragment, options){
    originalNavigate.apply(this, arguments);

    //your code here
}