2013-06-19 33 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