JQUERYMOBILE 页面显示在桌面上,但不显示在移动设备上
我在移动设备上动态显示内容时遇到问题。
我想通过以下代码写出包含值的列表:
$.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');
在桌面浏览器上一切正常,在移动设备上我尝试捕获错误,但没有任何结果。看起来一切正常,但我只看到空白页?
I have got problem with displaying dynamically content on mobile device.
I would like to writeout 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它不起作用的原因如下:在您完成添加内容之前,列表正在刷新。根据我的经验,将所有元素添加到列表中的最佳方法是执行类似
这样的操作,这样您也不会在 $.each 的每次传递中调用 $ 。您现在这样做的方式在计算上是昂贵的。是的,请接受。我是新人,可以使用代表:)。谢谢。
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
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.