二维数组转成一维数组输出 Vue

数组为:
"data": [
    {
        "parentName": "1",
        "childNode": [
            {
                "childName": "01",
                "childId": 1
            },
            {
                "childName": "02",
                "childId": 2
            }
        ]
    },
    {
        "parentName": "2",
        "childNode": [
            {
                "childName": "03",
                "childId": 3
            },
            {
                "childName": "04",
                "childId": 4
            }
        ]
    }

]

界面中:如果采用两层v-for遍历,则会序号为01 01 02 02 ;无法形成1 2 3 4;

采用一下代码,定义totalData,v-for:totalData。

mounted() {

//加载时执行的代码段

this.$nextTick(function () {

var _this = this;

// console.log(this.$route)

for(var n in _this.data){

for(var m in _this.data[n].childNode){

_this.totalData.push(_this.data[n].childNode[m])

} }

console.log(_this.totalData) }) },

 

猜你喜欢

转载自blog.csdn.net/weixin_36766850/article/details/84846823