I have got problem with displaying dynamically content on mobile device.
I would like to writ开发者_StackOverflow社区eout list with values, by this code:
$.each(mapdata, function(index, value){
//alert(index + ': ' + value.jmeno+value.lat+value.lng);
//document.write(value.jmeno);
//GET CURRENT GPS COORDS
//onLoad();
//GET CURRENT GPS COORDS
try {
//alert("SUCCESS");
$("ul").append("<li><img width=\"80px\" src=\"http://static.akcniceny.cz/" + value.img + "\"/><h3><a href=\"" + value.jmeno + "\">" + value.jmeno + "</a></h3><p>" + value.akcnicena + " Kč</p><p>" + value.pjmeno + "</p><div class=\"shop-distance\"></div><div id=\"lat\">" + value.lat + "</div><div id=\"lng\">" + value.lng + "</div></li>");
}
catch (err) {
alert("ERROR BY WRITEOUT");
}
});
$('ul').listview('refresh');
On desktop browser everything works fine, on mobile device I tryied catch error, but nothing. It seems, that everything works fine, but I see only blank white page?
The reason it doesn't work is the following: the list is refreshing before you've finished adding content. The best way to do all elements to a list, in my experience is do something like
var appendString;
$.each(data, function(index, value) {appendString = appendString + whatever});
$("ul").append(appendString);
$("ul").listview('refresh');
This way you also aren't calling the $ on EVERY pass of your $.each. The way you are doing it now is computationally expensive. And yeah, please accept. I'm new, could use the rep :). Thanks.
精彩评论