如何用js(jQuery)动态输出json数据
vardata=[{"keyid":"5","optype":"3","starttime":"2015-05-3009:30:00","endtime":"2015-0...
var data=[{"keyid":"5","optype":"3","starttime":"2015-05-30 09:30:00","endtime":"2015-05-30 09:31:00","palletbarcode":"T00006","slocbarcode":"C00001","deviceno":"001","stateid":"1","autoid":"0","isplan":"F"},
{"keyid":"4","optype":"2","starttime":"2015-05-30 09:30:00","endtime":"2015-05-30 09:31:00","palletbarcode":"T00004","slocbarcode":"C00002","deviceno":"001","stateid":"1","autoid":"0","isplan":"T"},
{"keyid":"3","optype":"2","starttime":"2015-05-30 09:30:00","endtime":"2015-05-30 09:31:00","palletbarcode":"T00003","slocbarcode":"C00011","deviceno":"001","stateid":"1","autoid":"0","isplan":"T"},
{"keyid":"2","optype":"1","starttime":"2015-05-30 09:30:00","endtime":"2015-05-30 09:31:00","palletbarcode":"T00002","slocbarcode":"C00043","deviceno":"001","stateid":"1","autoid":"0","isplan":"T"},
{"keyid":"1","optype":"1","starttime":"2015-05-30 09:30:00","endtime":"2015-05-30 09:31:00","palletbarcode":"T00001","slocbarcode":"C00001","deviceno":"001","stateid":"1","autoid":"0","isplan":"F"}]
主键 keyid
操作类型 optype 1:上架2:下架3:移仓4:收货5:打托6:出货
开始时间 starttime
结束时间 endtime
托盘条码 palletbarcode
仓位条码1 flocbarcode
仓位条码2 slocbarcode
叉车代码 deviceno
状态 stateid 0未解析(未确认)1已解析(已确认)
自动标志 autoid 0:自动1:手工
是否计划内 isplan T:计划内;F:计划外
计划编号 plankeyid
在ul里面循环输出li,li显示的内容为9:30--09:31 托盘T0001从仓位C0001下架
计划内操作这种形式 有字符串有变量 展开
{"keyid":"4","optype":"2","starttime":"2015-05-30 09:30:00","endtime":"2015-05-30 09:31:00","palletbarcode":"T00004","slocbarcode":"C00002","deviceno":"001","stateid":"1","autoid":"0","isplan":"T"},
{"keyid":"3","optype":"2","starttime":"2015-05-30 09:30:00","endtime":"2015-05-30 09:31:00","palletbarcode":"T00003","slocbarcode":"C00011","deviceno":"001","stateid":"1","autoid":"0","isplan":"T"},
{"keyid":"2","optype":"1","starttime":"2015-05-30 09:30:00","endtime":"2015-05-30 09:31:00","palletbarcode":"T00002","slocbarcode":"C00043","deviceno":"001","stateid":"1","autoid":"0","isplan":"T"},
{"keyid":"1","optype":"1","starttime":"2015-05-30 09:30:00","endtime":"2015-05-30 09:31:00","palletbarcode":"T00001","slocbarcode":"C00001","deviceno":"001","stateid":"1","autoid":"0","isplan":"F"}]
主键 keyid
操作类型 optype 1:上架2:下架3:移仓4:收货5:打托6:出货
开始时间 starttime
结束时间 endtime
托盘条码 palletbarcode
仓位条码1 flocbarcode
仓位条码2 slocbarcode
叉车代码 deviceno
状态 stateid 0未解析(未确认)1已解析(已确认)
自动标志 autoid 0:自动1:手工
是否计划内 isplan T:计划内;F:计划外
计划编号 plankeyid
在ul里面循环输出li,li显示的内容为9:30--09:31 托盘T0001从仓位C0001下架
计划内操作这种形式 有字符串有变量 展开
展开全部
写循环
<ul>
<script>
$().ready(function(){
for (var i = 0; i < data.length; i++) {
←←←←1←←←
if(data[i].optype=='2'){
document.write("<li>"+data[i].palletbarcode+"</li>");←←←←2←←←
}
}
});
</script>
</ul>
上面的代码能在ul内自动填充所有下架的托盘条码,并以li表现出来,如果你有别的需要显示出来,只需要在箭头2处添加不同的属性就可以,如果皮指你还有别的条件筛选,只需要在箭头1处添行握码加if块即档哪可。
<ul>
<script>
$().ready(function(){
for (var i = 0; i < data.length; i++) {
←←←←1←←←
if(data[i].optype=='2'){
document.write("<li>"+data[i].palletbarcode+"</li>");←←←←2←←←
}
}
});
</script>
</ul>
上面的代码能在ul内自动填充所有下架的托盘条码,并以li表现出来,如果你有别的需要显示出来,只需要在箭头2处添加不同的属性就可以,如果皮指你还有别的条件筛选,只需要在箭头1处添行握码加if块即档哪可。
追问
能把具体的代码写出来吗 本人新手 谢谢了
追答
。。。新手就让你做这个。。。。。。
↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
for (var i = 0; i "+data[i].starttime+"托盘"+data[i].palletbarcode+"从仓位"+data[i].slocbarcode
+ms+"");
}
把上面整个for替换掉就可以了。。。。。。。这变量名字起的我也是醉了
展开全部
楼上的能实现 就是用循环
也可以用eval去做
个人觉得eval比较好点
也可以用eval去做
个人觉得eval比较好点
追问
能把具体的代码写出来吗 本人新手 谢谢了
追答
$(function(){
$.ajax({
type:'post',
url:"index.php",
data:"id=1",
dataType:"json",
success:function(data){
var data = eval(data);
var str = '';
for( var i in data){
//这里吧starttime与entime处理一下取出想要的时间
var start = (data[i].starttime).substr(11,5);
var end = (data[i].starttime).substr(11,5);
if(data[i].optype == 1){
type = "上架";
}else if(data[i].optype == 2){
type = "下架";
//根据对应关系判断出来
}else if........
str += ''+start+"-"+end+" 托盘"+data[i].palletbarcode+"从仓位"+data[i].slocbarcode+type"";
}
document.write(str);
}
})
})
有问题追下
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询