How to pass parameters while changing the page in JQuery Mobile?

后端 未结 2 1407
被撕碎了的回忆
被撕碎了的回忆 2020-12-15 00:45

I\'ve searched around stackoverflow but didnt find a proper solution to programmatically change the jqm page and pass a (get) parameter with it. I\'m new to jqm so maybe I g

2条回答
  •  情歌与酒
    2020-12-15 01:02

    I see that this question was already answered and comments were traded on the answer, and I have also faced this issue. Using jQuery Mobile as it is intended allows for ajax loading, and therefore no need for a browser refresh unless instigated by a user, correct? And if a user is refreshing for some reason, that means that the site or app isn't functioning the way it is exptected to since most users wouldn't refresh without a frustrating cause.

    In saying so, as suggested by the comments creating a variable is an efficient way of passing data from "page" to "page". However, my suggestion in doing so is to instead create a global variable to contain site information.

    $('#elemControlToChangeBy').on("tap", function(oEvent)
    {
       oMyNameSpace.PageDataObj = oDataObj;
    
       $.mobile.changePage("#elemPage", {transition : "type"})
    });
    
    $("elemPage").on("pageshow", function()
    {
       var oDataObj = oMyNamespance.PageDataObj;
    
       //Use the data...
    });
    

    Obviously the code will have to modified to your coding conventions, but the concepts are there:

    • Store your data or access it by some other means
    • Place the data in a contained variable to prevent any overwrites by external code
    • Access the data object variable when you arrive at the next page

    There are other routes, as already stated(local storage, ect) so I won't go touching on that since the information is there already.

    As stated above, I've run into this issue, and my suggestion is to use jQuery Mobile as it was intended and use your own code base to create and store variables using an organized object hierarchy. How you organize it is of your choice, which is precisely what makes javascript such a fantastic language.

    We've become too dependent on libraries to solve simple issues that the authors leave to us to solve using our inventive and personal standard driven methods. Happy Coding to all, with an encouragement to build, not just design!

提交回复
热议问题