使用更改页面传递jquery移动参数

时间:2014-03-05 06:48:16

标签: jquery mobile

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它刷新了页面但没有显示测试细节。这个问题是什么?

2 个答案:

答案 0 :(得分: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 :(得分: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.
相关问题