2014-03-05 27 views
1
i have in jquery mobile when i passing parameter using change page. 

$("#mytest-listview div.mytest-title a").live('click', function (event,data) { 
    var cid = $(this).attr('id'); 
    console.log(cid); 

    $.mobile.changePage('../mytestdetail/',{ type: "get", data: {"id":cid} , reloadPage:false, changeHash:true }); 

    $('#pgMyTestDetail').live('pageshow', function(){ 
     var id = $.urlParam('id'); 
     doLoadMyTest(id); 

    }); 

    $.urlParam = function(name){ 
     var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href); 
     return results[1] || 0; 
    } 
    event.preventDefault(); 

}); 

当我mytest的标题点击它传递的mytest的ID,以URL,然后我得到的id值并显示mytest的所有细节。这里是url/test/testdetail /?id = 26,但是当我得到测试详细信息页面时,我点击了ctrl + R它刷新了页面,但没有显示测试细节。有什么问题?jQuery Mobile的参数传递使用变化页

+0

如果你仍然有这个麻烦,我[插件](https://github.com/CameronAskew/jquery.mobile.paramsHandler)可能会帮助 –

回答

1

从版本1.4开始,jQuery Mobile does not support page parameters。对于版本1.5,roadmap包含“根据规格的哈希/查询参数”。

解决方法是使用自定义路由器,如Cameron Askew's paramsHandler

其他路由器选项包括jquerymobile-router,在撰写本文时,这些选项并未与jQuery Mobile 1.4或Backbone's router保持同步,这可能需要大量集成以支持jQuery Mobile的功能。

或者,clickvclick事件可以被拦截并直接处理以增加参数支持,例如,在页面转换之前将参数保存在变量中。

+1

我认为这些路由器可能出日期。我最近为jQM 1.4 –

+1

@CameronAskew创建了一个[插件](https://github.com/CameronAskew/jquery.mobile.paramsHandler),太棒了!我已经更新了我的答案。 –

0
$("#mytest-listview div.mytest-title a").live("click", function (e) { 
      e.preventDefault(); 
      var cid = $(this).attr('id'); 
      console.log(cid); 
      $.mobile.changePage('../mytestdetail/', { type: "get", data: {"id": cid}, reloadPage: false, changeHash: true }); 


     }); 
    //}); 

    $(document).on("pageinit", "#pgTestDetail", function (e) { 
     var cid = (($(this).data("url").indexOf("?") > 0) ? $(this).data("url") : window.location.href).replace(/.*id=/, ""); 
     doLoadTest(cid); 


I write above code and its works great even refresh the page using ctrl+r.