美文网首页
转换后台返回的键值对

转换后台返回的键值对

作者: 大筒木周助 | 来源:发表于2019-07-10 14:48 被阅读0次

{

  "data": [

    {

      "id": "2",

      "pid": "1",

      "name": "Joyce@163.com",

      "uid": "2",

      "children": [

        {

          "id": "3",

          "pid": "2",

          "name": "flow01@163.com",

          "uid": "3",

          "children": []

        },

        {

          "id": "4",

          "pid": "2",

          "name": "0",

          "uid": "4",

          "children": []

        },

        {

          "id": "33",

          "pid": "2",

          "name": "0",

          "uid": "37",

          "children": []

        },

        {

          "id": "101",

          "pid": "2",

          "name": "1195154798@qq.com",

          "uid": "116",

          "children": []

        },

        {

          "id": "102",

          "pid": "2",

          "name": "device02@163.com",

          "uid": "117",

          "children": []

        },

        {

          "id": "103",

          "pid": "2",

          "name": "flow@163.com",

          "uid": "118",

          "children": []

        }

      ]

    }

  ],

  "code": 0,

  "message": ""

}

后台返回的数据是name的键值对,但是业务需求要以title的键值对,方法如下

var treeList = JSON.parse(JSON.stringify(data).replace(/name/g, 'title'))

console.log(treeList)

相关文章

网友评论

      本文标题:转换后台返回的键值对

      本文链接:https://www.haomeiwen.com/subject/eerhkctx.html