javascript - json double-level nesting, how to traverse and concatenate strings?
黄舟
黄舟 2017-06-24 09:43:35
0
2
979

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"
                }
            ]
        }                  
    ]
}

}
Like this, I need to loop through the concatenated strings and put them on the page. How to do it? ? ? I'm a newbie.

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(2)
曾经蜡笔没有小新
    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>
巴扎黑

It shouldn’t be difficult to provide ideas to the questioner without writing code, loop to determine the data type, and then recurse

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template