2

backbone.js @ でテスト ケースを作成します: http://jsfiddle.net/VWBvs/5/

ルートは次のように定義されます

var AppRouter = Backbone.Router.extend({
        routes: {
            "/posts/:id" : "getPost",
            "/download/*path": "downloadFile",  
            "*actions" : "defaultRoute"
        },
        getPost: function(id) {
            alert(id);
        },
        defaultRoute : function(actions){
            alert(actions);
        },
        downloadFile: function( path ){ 
            alert(path); // user/images/hey.gif 
        },
        loadView: function( route, action ){ 
            alert(route + "_" + action); // dashboard_graph 
        }
    });

    var app_router = new AppRouter;

    Backbone.history.start();​

機能を変えると

  defaultRoute : function(actions){
            alert(actions);
        },

defaultRoute : function(actions){
            var action = actions
        },

他のすべてのルートは機能しません。つまり、ダイアログはポップアップしません。

しかし、コードを再変更すると、すべて問題ありません。

それは本当に奇妙で、私を混乱させます。心からSOS……

4

1 に答える 1

4

あなたが持っているように、コードdefaultRouteはこれまでに起動する唯一のルートです。他の 2 つのルートを起動する場合は、先頭のスラッシュを削除する必要があります。

routes: {
  "posts/:id" : "getPost",
  "download/*path": "downloadFile",  
  "*actions" : "defaultRoute"
}
于 2012-04-17T03:57:52.410 に答える