JSON:
[{
"Id": 15,
"SiteId": 6,
"CategoryId": 25,
"AttrName": "颜色",
"Sort": 0,
"Status": 1,
"IsRequired": true,
"AddDate": "/Date(1493537367920)/",
"List": [{
"Id": 14,
"SiteId": 6,
"CategoryId": 25,
"GoodAttrId": 15,
"AttrValue": "#F6358A",
"DisplayValue": "红色",
"Sort": 1,
"Status": 1,
"AddDate": "/Date(1493479729483)/"
},
{
"Id": 15,
"SiteId": 6,
"CategoryId": 25,
"GoodAttrId": 15,
"AttrValue": "#3BB9FF",
"DisplayValue": "蓝色",
"Sort": 2,
"Status": 1,
"AddDate": "/Date(1493479729487)/"
},
{
"Id": 16,
"SiteId": 6,
"CategoryId": 25,
"GoodAttrId": 15,
"AttrValue": "#000000",
"DisplayValue": "黑色",
"Sort": 3,
"Status": 1,
"AddDate": "/Date(1493479729487)/"
},
{
"Id": 17,
"SiteId": 6,
"CategoryId": 25,
"GoodAttrId": 15,
"AttrValue": "#FFFFFF",
"DisplayValue": "白色",
"Sort": 4,
"Status": 1,
"AddDate": "/Date(1493479729487)/"
}]
},
{
"Id": 16,
"SiteId": 6,
"CategoryId": 25,
"AttrName": "规格",
"Sort": 2,
"Status": 1,
"IsRequired": true,
"AddDate": "/Date(1493537843597)/",
"List": [{
"Id": 18,
"SiteId": 6,
"CategoryId": 25,
"GoodAttrId": 16,
"AttrValue": "8G",
"DisplayValue": "8G",
"Sort": 1,
"Status": 1,
"AddDate": "/Date(1493537843607)/"
},
{
"Id": 19,
"SiteId": 6,
"CategoryId": 25,
"GoodAttrId": 16,
"AttrValue": "16G",
"DisplayValue": "16G",
"Sort": 2,
"Status": 1,
"AddDate": "/Date(1493537843607)/"
}]
}]
我使用
$.each(data, function (k, p) {
var str="<div class=\"form-group\">";
str+="<label class=\"control-label col-md-2\">"+p.AttrName+"</label>";
str+="<div class=\"col-md-8\">";
$.each(data.List,function(k1,p1){
});
str+="</div></div>";
$("#GoodAttrs").append(str);
});
只能解析出第一层,第二层死活解析不出来。
要求格式:
颜色
红色 蓝 色 黑色
规格
8G 16G 32G
把问题发出来,自己就找到问题了。。。。也是醉了。
第二层应该是p.List