2012-04-28 6 views
2

私のコードを発射していない以下の通りです:BACKBONE.JSルートは正しく

var AppRouter = Backbone.Router.extend({ 

    _data: null, 
    _length: 0, 
    _index: null, 
    _todos: null, 

    routes: { 
     "*action": "index", 
     "category/:name": "hashcategory" 
    }, 

    initialize: function(options){ 
     this._data = options.data; 
     this._todos = new TodosCollection(options.data); 
     this._length = this._todos.length; 
     this._index = new CategoriesView({collection: this._todos}); 
    }, 

    index: function(){ 
     this._index.render(); 
    }, 

    hashcategory: function(name){ 
     console.log('started'); 
    } 
}); 

initializeRouter = function (router) { 
    Backbone.history.start({ pushState: true }); 
    $(document).on('click', 'a:not([data-bypass])', function (evt) { 

     var href = $(this).attr('href'); 
     var protocol = this.protocol + '//'; 

     if (href.slice(protocol.length) !== protocol) { 
      evt.preventDefault(); 
      router.navigate(href, true); 
     } 
    }); 
    return router; 
}; 


var start = function(){ 
    p = $.ajax({ 
     url: 'data/todolist.json', 
     dataType: 'json', 
     data: {}, 
     success: function(data) { 
      var approuter = initializeRouter(new AppRouter({data: data})); 
     } 
    });  
}; 

私はhref = "category/num1" attibuteを持っている私のhtmlで<a>リンクを持っています。しかし、リンクをクリックするたびに、常にsecurity errorが火かき棒に表示されます。実際には私はちょうど1つのindex.htmlページを持って、何をしたいのですか?folder/index.html/category/num1のような偽のhtmlページを作るためにそれに文字列を追加すると、すべてのものが現在のページにレンダリングされます。しかし、私がリンクを張ったときに表示されるURLはfolder/category/num1です。このパスは実際に私のフォルダには存在しないので、セキュリティエラーが表示されていると思います。

どのように修正する必要がありますか?別のhtmlページと対応するフォルダを作成する必要がありますか?または、すべてのルーティングを1つのindex.htmlページで行うことはできますか?

答えて

1

がHREFで#を入れてみてください、

href = "#category/num1" 
+0

THXのように、URLは私が期待したものに近いですが、対応するルートはまだ正常に起動しません。 – chaonextdoor

関連する問題