Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Backbone.js 在主干.Router.navigate()之后运行函数_Backbone.js_Coffeescript - Fatal编程技术网

Backbone.js 在主干.Router.navigate()之后运行函数

Backbone.js 在主干.Router.navigate()之后运行函数,backbone.js,coffeescript,Backbone.js,Coffeescript,我想在backbone.navigate调用后运行一个函数(呈现flash消息)。可能吗?我目前已连接到all事件,并检查eventname是否以“route:”开头。但在添加我的消息之前,这会触发得太早。。。所以我想在路线完成后跑步 # intercept all router navigate and render flash messages if any renderFlashMessengesOnNavigate = (evt) => if evt.indexOf("rout

我想在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
试试这个:

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

    //your code here
}
试试这个:

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

    //your code here
}

定义“完成”路线的含义。你是说路由器执行了路由功能吗?或者,您的意思是路由函数创建的视图已完成对其DOM元素的渲染?请定义路由“完成”的含义。你是说路由器执行了路由功能吗?或者,您的意思是路由函数创建的视图已完成对其DOM元素的渲染?