我的路由骨干有问题。我在产品索引(localhost:3000 /产品)中调用Backbone.history.start()。路线:
'': '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')
注意:所有标记a都有data-ajax ='false'并且有一些配置:
$(document).bind('mobileinit', function() {
$.mobile.ajaxEnabled = false;
$.mobile.linkBindingEnabled = false;
$.mobile.hashListeningEnabled = false;
$.mobile.pushStateEnabled = false;
});
当我在页面'localhost / products#123'并且点击'a'链接'localhost:3000 / products#123 / items / 456'时,会发生错误。它警告'错误加载页'然后网址自动更改为'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 :(得分: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)
如果是的话请调试,并为我找出id的值。
谢谢