helo 我已经努力设计在页面中随机打印的 json 值的样式,这里有 4 个类别,我用 javascript 做的是找到包含许多对象的 json 数组的长度,然后取类型 id,因为它是在所有数组中通用,确定它们是否属于0,1,2,3类别,然后打印json数组中的所有元素等等,这里我想为每个类别创建表并将所有对应的id推送到表行。
var txt = '<?php echo $response ?>';
//alert(txt);
//var jsonData = eval ("(" + txt + ")");
var jsonData = JSON.parse(txt);
for (var i = 0; i < jsonData.account_detail.length; i++) {
var counter = jsonData.account_detail[i];
//console.log(counter.counter_name);
//alert(counter.type);
document.write("<table border="0" width="500>">")
if(counter.type=="0")
{
document.write(counter.building_name);
document.write(counter.org_name);
document.write(counter.user_name);
document.write(counter.name);
document.write(counter.loc_name);
document.write(counter.email_id);
document.write(counter.password);
}
if(counter.type=="1")
{
document.write(counter.user_name);
document.write(counter.name);
document.write(counter.password);
document.write(counter.email_id);
}
if(counter.type=="2")
{
document.write(counter.building_name);
document.write(counter.org_name);
document.write(counter.user_name);
document.write(counter.opr_code);
document.write(counter.name);
document.write(counter.loc_name);
document.write(counter.email_id);
document.write(counter.password);
}
if(counter.type=="3")
{
document.write(counter.building_name);
document.write(counter.org_name);
document.write(counter.machine_type);
document.write(counter.activate_status);
document.write(counter.machine_name);
document.write(counter.entrance_exit_name);
document.write(counter.entrance_or_exit);
document.write(counter.loc_name);
document.write(counter.activation_code);
}
}
document.write("</table>")