jquery mobile 的新手和解析 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>';
}
最佳答案
如果我错了,请纠正我,据我在阅读您的代码时所知,可能存在多个问题
首先,g_html变量的引用,你为什么不在lochtml函数中返回html,在你的for循环中,像这样构建HTML , 更易读
for (var i=0;i<res.length;i++){
g_html=g_html+lochtml('loc',i,r...)
}
其次,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>
我认为这不是 jQuery Mobile 对 data-role="collapsible-set"内容的期望,应该只有 第四,是否需要 最后,我认为 collapsibleset('refresh') 应该在 关于ajax - jquery mobile可折叠和galaxy tab 10.1 json响应给出随机响应,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/13829283/
相关文章:
javascript - Ajax 发布成功(在浏览器中显示)但 $_POST 中没有数据
json - 如何使用 Powershell 访问 Restful 网络服务?
来自 ajax 加载的 div 内部的 jquery 动画
javascript - 如何使用ajax一键点击动态显示多个表格
javascript - 根据 jQuery 中多个实例的另一个元素高度设置高度
php - 如何使用 jquery bassistance 插件向占位符提供错误信息
javascript - 如何在提交事件时将窗口位置设置为底部?
javascript - JQuery 更改时发出 ajax 请求
javascript - 如何只获取 JSON 数据的第一个元素?
java - Jackson转换执行时间/顺序和@JsonAnySetter
上一篇:javascript - JSON.stringify 抛出 RangeError : Invalid string length for huge objects
下一篇:python - Django:使用 Javascript 在我的模板中解析 JSON
相关文章:
python - datetime.date(2014, 4, 25) 在 Django 中不是 J
php - json_encode 不使用 html 字符串作为值
json - Spring Boot Actuator 端点的 pretty-print JSON
json - HTTPResponse 对象 -- JSON 对象必须是 str,而不是 'byte
javascript - 如何在 console.log 中打印 JSON 数据?
python - Django:使用 Javascript 在我的模板中解析 JSON
python - 如何从一个文件中提取多个 JSON 对象?