javascript - json 双层嵌套 ,如何遍历拼接字符串?
本文介绍了javascript - json 双层嵌套 ,如何遍历拼接字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
var response = {
"msg": "success",
"code": 200,
"data": {
"total": 328880,
"ipInfo": [
{
"count": 3155,
"key": "315.230.145.246",
"subList": [
{
"count": 3154,
"key": "8058230"
},
{
"count": 1,
"key": "713467"
}
]
},
{
"count": 3454645,
"key": "215.230.145.246",
"subList": [
{
"count": 6154,
"key": "8058240"
},
{
"count": 1124,
"key": "1155530"
}
]
}
]
}
}
像这种,我需要循环遍历拼接字符串放到页面上,怎么做???本人菜鸟萌新。
解决方案
var tempStr = '';
response.data.ipInfo.forEach(function (item) {
item.subList.forEach(function (subItem) {
tempStr += "<p><span>" + subItem.count + "</span><span>" + subItem.key + "</span></p>";
});
});
Vue:
<tr v-for="item in ipInfo">
<td v-for="subItem in item">{{ subItem.count }} - {{subItem.key }}</td>
</tr>
这篇关于javascript - json 双层嵌套 ,如何遍历拼接字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文