Jquery mobile 主干js,路由错误,url自动更改
我的主干路由有问题。我在产品索引(localhost:3000/products)中调用Backbone.history.start()。路线: 注意:所有标记a都有数据ajax='false',并有一些配置:Jquery mobile 主干js,路由错误,url自动更改,jquery-mobile,backbone.js,backbone-routing,Jquery Mobile,Backbone.js,Backbone Routing,我的主干路由有问题。我在产品索引(localhost:3000/products)中调用Backbone.history.start()。路线: 注意:所有标记a都有数据ajax='false',并有一些配置: $(document).bind('mobileinit', function() { $.mobile.ajaxEnabled = false; $.mobile.linkBindingEnabled = false; $.mobile.
$(document).bind('mobileinit', function() {
$.mobile.ajaxEnabled = false;
$.mobile.linkBindingEnabled = false;
$.mobile.hashListeningEnabled = false;
$.mobile.pushStateEnabled = false;
});
当我在“localhost/products#123”页面并单击标记“a”link“localhost:3000/products#123/items/456”时,会发生此错误。它警告“加载页面出错”,然后url自动更改为“localhost:3000/123/items/456”,控制台中出现错误:“GET-localhost:3000/123/items/456 404(未找到)” 我的路由文件:
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 } )
当您调用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的值
谢谢请分享您的路线代码以及拨打GET电话的地点。我添加了func路线。请查看我在“localhost/products#123”页面并单击带有href“localhost:3000/products#123/items/456”的标记“a”时发生的错误。它不会转到项目显示功能。产品_show func工作正常,id值为:123尝试按照此答案操作,但仍会出现错误。是否使用“导航”属性进行导航?appFsMvc.App.navigate(“创建”{trigger:true});我不知道你在用什么。我只是调用Backbone.history.start()。我使用gem'backbone-on-rails'添加了路径:“test”(localhost:3000/products#test)运行正常。但“test/abc”(localhost:3000/products#test/abc)是上述错误。我是否缺少主干网或移动设备的配置??
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)