I’m loading a list view full of items via getJSON.
But when I tap a list view item I want to arrive to the Details page for that item.
Now, in ASP.NET for example you would do Details.aspx?Id=1 but how will I do in jQuery Mobile? When I get the objects via my getJSON method. Do I need to store them in an array or something?
I should add that in my current getJSON response, none of the objects has an ID tied to it. But this is just a sandbox, I’m just playing around with jQuery Mobile and getting my feed from Flickr:
$(function() {
$.mobile.showPageLoadingMsg("Laddar...");
$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?",
{
tags: "cat",
tagmode: "any",
format: "json"
},
function(data) {
$.each(data.items, function(i,item){
$('#list')
.append('<li><a><img src="images/de.png" class="ui-li-icon">' + item.author + '</a></li>')
.listview('refresh');
});
$.mobile.hidePageLoadingMsg();
});
});
What is the praxis in setting up “Details pages” in jQuery Mobile? Should I create the in my code above with id=x and then in some way get a object at that index in my array (which I haven’t created yet)?
First off there are some things you can do to greatly improve the performance of your code:
Now you can add a
clickevent handler to the links in the#listlist-view and create the necessary pseudo-pages for jQuery Mobile:Here is a demo: http://jsfiddle.net/m4Yt8/
I’m not sure what your JSON looks like so I can’t say for sure how to add data from the JSON object into the new pages, however the above template should be pretty close.