cb5*_*b52 27 ajax jquery json collapsable jquery-mobile
jquery移动相当新,解析json的新手 - 做了很多研究无济于事.在settimeout函数中尝试了10秒延迟
我的应用程序在我的三星galaxy s2上正常工作,但在我的三星Galaxy平板电脑10.1上它做了以下.
使用最新jquery 1.2.0
和jquery-1.7.2
我打电话getlocations2.php
,如果我返回四个或更少的项目,可折叠集合正确打开和关闭.如果我退回5件或更多物品:
感谢您的任何提示:
代码:
function doajax2($vurl,$vdata,$vtype,$vfrom){
$.ajax({
url: $vurl,
dataType: 'json',
data:$vdata,
async: false,
success: function(rtndata) {
$.mobile.hidePageLoadingMsg(); //alert(result.toSource())
rtndata2=(JSON.stringify(rtndata, null, 4));
rtndata2=rtndata2.substring(13);
rtndata2=rtndata2.slice(0, -2)
var res = eval(rtndata2);
$('.displaylocations').html('');
g_html=res[0].brand;
if (res[0].id> -1){
g_html=g_html+'<div data-role="collapsible-set" data-theme="f" >';
for (var i=0;i<res.length;i++){
//for (var i=0;i<6;i++){
lochtml('loc',i,res[i].locid,res[i].loccode1,res[i].head,res[i].desc,res[i].lang,res[i].lat1,res[i].long1,res[i].img1,res[i].limit);
}
g_html=g_html+'</div>';
}
console.log('g_html'+g_html);
$('.displaylocations').css('display','none');
$(".displaylocations").html(g_html);
// $(".displaylocations").html(str);
setTimeout(function(){ //make sure displaylocations has been updated
$('#lhead2').html('Tuhura <span lang="en">Locations</span>');
$('.displaylocations').trigger('create');
$('.displaylocations').css('display','block');
$( ".displaylocations" ).collapsibleset( "refresh" );
},300);
},
error: function(faildata){
switch ($vfrom) {
case "region" : $("#lhead3").html('Region Info Unavailable...');break
case "locs" : $("#lhead2").html('Locations Unavailable...');break;
}
}
});
}
function lochtml($vtype,$vno,$locid,$loccode1,$head,$desc,$vlang,$vlat1,$vlong1,$img1,$limit) {
console.log('lochtml '+$desc);
g_html=g_html+ "<div class='locgoh'>";
g_html=g_html+ '<a href="#" onclick="getsitedetails('+"'gps','"+$locid+"','"+$loccode1+"','s','sites','"+$vlang+"',1,0,'x',"+$vlat1+","+$vlong1+')">';
g_html=g_html+ '<img src="http://tuhtop.co.nz/images/rightarrow.png" width="30px" height="30px" /></a>';
g_html=g_html+ '</div>';
g_html=g_html+'<div data-role="collapsible" class="loccollapse" data-theme="f" div="coldiv">';
g_html=g_html+ '<h3>'+$head+'</h3>';
g_html=g_html+ '<p><div class="locli0">';
g_html=g_html+ '<span class="li1">' +$desc+ '</span>';
g_html=g_html+ '<span class="li2"><a href="#" onclick="getsitedetails('+"'gps','"+$locid+"','"+$loccode1+"','s','sites','"+$vlang+"',1,0,'x',"+$vlat1+","+$vlong1+')">';
g_html=g_html+ '<img src=\''+$img1+'\' width=\'120"\' height=\'120\' alt=\''+$img1+'\'/></a>';
g_html=g_html+ '</span>';
g_html=g_html+ '</div></p>';
g_html=g_html+'<div class="clearfloat"></div>';
g_html=g_html+'</div>';
}
Run Code Online (Sandbox Code Playgroud)
如果我错了,请纠正我,据我在阅读代码时所知,可能存在多个问题
首先,g_html变量的引用,为什么不在函数lochtml和for循环中返回html,像这样构建HTML,它更具可读性
for (var i=0;i<res.length;i++){
g_html=g_html+lochtml('loc',i,r...)
}
Run Code Online (Sandbox Code Playgroud)
其次, g_html的初始值被设置为res[0].brand,它的值是多少?
第三,这是为可折叠集 div 生成的内容:
the res[0].brand above
<div data-role="collapsible-set" data-theme="f">
<div class='locgoh'>
<a ...>
<img />
</a>
</div>
<div data-role="collapsible" class="loccollapse" data-theme="f" div="coldiv">
<h3>...</h3>
<p>...</p>
<div class="clearfloat"></div>
</div>
...
...
</div>
Run Code Online (Sandbox Code Playgroud)
这不是 jQuery Mobile 对 data-role="collapsible-set" 内容的期望,我认为, <div data-role="collapsible -set "内应该只有<div data-role="collapsible"> > . 我建议您将<div class='locgoh'>移至<h3>内
第四,是否需要<div class="clearfloat">?您是否将标签p漂浮在可折叠的内部?之前我在一些 jQM 小部件中使用“float”时遇到了一些问题。另外,如果不需要clearfloat,最好将其删除。
最后,我认为应该在<div data-role="collapsible-set">而不是其容器上调用collapsibleset('refresh') 。