开发者

JQUERYMOBILE page displayed on desktop, but not on mobile device

开发者 https://www.devze.com 2023-02-22 01:21 出处:网络
I have got problem with displaying dynamically content on mobile device. I would like to writ开发者_StackOverflow社区eout list with values, by this code:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消