0

在我的应用程序中,我有主链接和子链接,因此每个链接都会更改,我正在调用适当的函数。

因此,每次路由器更改时,我都需要调用我的导航功能来执行此操作,我是这样做的:

var appRouters = Backbone.Router.extend({
        routes:{
            "general/":"defaultRoute",
            "general/:page/":"generalSublinks",
            "repositories/":"repositories",
            "repositories/:page/":"repositoriesSublinks",
            "savedSearch/":"savedSearch",
            "favourites/":"favourites",
            "reports/":"reports",
            "preferences/":"preferences",
            "preferences/:page/":"preferencesSubLinks",
            '*path':  'defaultRoute'
        },
        initialize:function(){
            this.bind("all", this.navigationUpdate); // calling 3 times each navigation change.. how to solve this?
        },
        navigationUpdate:function(){
            new naviView();
        },
        defaultRoute:function(){
            new dBView();
        },
        generalSublinks:function(id){
            if(id === "dashBoard"){
                this.defaultRoute();
            }else if(id === "myTask"){
                new myTaskView();
            }else if (id === "myDocument"){
                new myDocView();
            }else if (id === "myTemplate"){
                new myTempView();
            }else if (id === "search"){
                new mySearchView();
            }
        }

});

它工作正常。但我被navigationUpdate - 称为 3 次。有什么办法可以解决这个问题..?

4

1 回答 1

2

这是因为你在听all

尝试添加它以查看您正在接收哪些事件:

    navigationUpdate:function(eventName){
         console.log(eventName);
         new naviView();
    }

要修复它,您应该能够做到这一点:

this.on("route", this.navigationUpdate, this);
于 2013-07-03T14:25:16.547 回答