2013-06-19 31 views
0

我有路由骨幹問題。我在產品索引(localhost:3000/products)中調用Backbone.history.start()。路線:骨幹js,路由錯誤和url自動更改

'': 'product_index' 
':id': 'product_show' (tag 'a' link 'localhost:3000/products#123') 
':id/items/:item_id': 'item_show' (tag 'a' link 'localhost:3000/products#123/items/456') 

注:所有標籤有數據阿賈克斯=「假」,並有一定的配置:

$(document).bind('mobileinit', function() { 
     $.mobile.ajaxEnabled = false; 
     $.mobile.linkBindingEnabled = false; 
     $.mobile.hashListeningEnabled = false; 
     $.mobile.pushStateEnabled = false; 
     }); 

的錯誤,當我在頁面是發生「本地主機/產品#123」並點擊標記'a'鏈接'localhost:3000/products#123/items/456'。它警告'錯誤加載頁'然後url自動更改爲'localhost:3000/123/items/456',並在控制檯中有錯誤:'GET localhost:3000/123/items/456 404(Not Found)'

我的路由文件:

class Braindu.Routers.Mobile extends Backbone.Router 
    initialize: (options) -> 
    @products = new Braindu.Collections.Products() 
    @products_view = new Braindu.Views.MobileProductsIndex(collection: @products, id_product_el:'product-index-page') 

    routes: 
    '' : 'product_index' 
    ':id' : 'product_show' 
    ':id/items/:item_id': 'item_show' 


    product_index: -> 
    @product_index_view.render() 

    product_show:(id) -> 
    $.mobile.changePage("#product-show-page" , { reverse: false, changeHash: false }) 
    current_product_model = @product_index_view.product_collection.where({_id: id})[0] 
    if current_product_model != null && current_product_model != undefined 
     @product_index_view.render_current_product(current_product_model) 

    item_show:(id, item_id)-> 
    console.log 'item showwwwwwwwwwwwwwwwwwwwwwww' 
    $.mobile.changePage("#object-card-page" , { reverse: false, changeHash: false }) 
+0

請分享您的路由代碼以及您進行GET調用的位置。 – Harish

+0

我添加func路線。請參閱 –

回答

0

當您調用localhost時:3000/123/items/456是否在調用以下函數?

product_show:(id) -> 
    $.mobile.changePage("#product-show-page" , { reverse: false, changeHash: false }) 
    current_product_model = @product_index_view.product_collection.where({_id: id})[0] 
    if current_product_model != null && current_product_model != undefined 
     @product_index_view.render_current_product(current_product_model) 

如果是這樣,請調試並找出我的身份證的價值。

謝謝

+0

當我在頁面'localhost/products#123'中,並且在href'localhost:3000/products#123/items/456'中點擊標記'a'時發生錯誤。 它不去item_show函數。 product_show func工作正常,id值爲:123 –

+0

嘗試按照此答案,但仍然出現錯誤。 http://stackoverflow.com/questions/10870948/how-to-get-this-backbone-route-to-work?rq=1 –

+0

你使用導航屬性來導航? appFsMvc.App.navigate(「create」,{trigger:true}); – Harish