嵌套对象如何转换成树形结构?

原数据格式:

var data = {
  "北京": {
    "id": 1000,
    "市": {
      "东城": {
        "id": 1378,
        "区县": {
          "东城区": 110101
        }
      },
      "西城": {
        "id": 1379,
        "区县": {
          "西城区": 110102
        }
      },
      "朝阳": {
        "id": 1382,
        "区县": {
          "朝阳区": 110105
        }
      },
      "丰台": {
        "id": 1383,
        "区县": {
          "丰台区": 110106
        }
      },
      "石景山": {
        "id": 1384,
        "区县": {
          "石景山区": 110107
        }
      },
      "海淀": {
        "id": 1385,
        "区县": {
          "海淀区": 110108
        }
      },
      "门头沟": {
        "id": 1386,
        "区县": {
          "门头沟区": 110109
        }
      },
      "房山": {
        "id": 1387,
        "区县": {
          "房山区": 110111
        }
      },
      "通州": {
        "id": 1388,
        "区县": {
          "通州区": 110112
        }
      },
      "顺义": {
        "id": 1389,
        "区县": {
          "顺义区": 110113
        }
      },
      "昌平": {
        "id": 1390,
        "区县": {
          "昌平区": 110114
        }
      },
      "大兴": {
        "id": 1391,
        "区县": {
          "大兴区": 110115
        }
      },
      "怀柔": {
        "id": 1392,
        "区县": {
          "怀柔区": 110116
        }
      },
      "平谷": {
        "id": 1393,
        "区县": {
          "平谷区": 110117
        }
      },
      "密云": {
        "id": 1394,
        "区县": {
          "密云区": 110118
        }
      },
      "延庆": {
        "id": 1395,
        "区县": {
          "延庆区": 110119
        }
      }
    }
  },
  "上海": {
    "id": 2000,
    "市": {
      "黄浦": {
        "id": 2396,
        "区县": {
          "黄浦区": 310101
        }
      },
      "徐汇": {
        "id": 2398,
        "区县": {
          "徐汇区": 310104
        }
      },
      "长宁": {
        "id": 2399,
        "区县": {
          "长宁区": 310105
        }
      },
      "静安": {
        "id": 2400,
        "区县": {
          "静安区": 310106
        }
      },
      "普陀": {
        "id": 2401,
        "区县": {
          "普陀区": 310107
        }
      },
      "虹口": {
        "id": 2403,
        "区县": {
          "虹口区": 310109
        }
      },
      "杨浦": {
        "id": 2404,
        "区县": {
          "杨浦区": 310110
        }
      },
      "闵行": {
        "id": 2405,
        "区县": {
          "闵行区": 310112
        }
      },
      "宝山": {
        "id": 2406,
        "区县": {
          "宝山区": 310113
        }
      },
      "嘉定": {
        "id": 2407,
        "区县": {
          "嘉定区": 310114
        }
      },
      "浦东": {
        "id": 2408,
        "区县": {
          "浦东区": 310115
        }
      },
      "金山": {
        "id": 2409,
        "区县": {
          "金山区": 310116
        }
      },
      "松江": {
        "id": 2410,
        "区县": {
          "松江区": 310117
        }
      },
      "青浦": {
        "id": 2411,
        "区县": {
          "青浦区": 310118
        }
      },
      "奉贤": {
        "id": 2413,
        "区县": {
          "奉贤区": 310120
        }
      },
      "崇明": {
        "id": 2414,
        "区县": {
          "崇明区": 310151
        }
      }
    }
  },
  "广东":{
      "id":4000,
      "市":{
          "阳江":{
              "id":4109,
              "区县":{
                  "江城区":441702,
                  "阳东区":441704,
                  "阳西县":441721,
                  "阳春市":441781
              }
          },
          "湛江":{
              "id":4110,
              "区县":{
                  "赤坎区":440802,
                  "霞山区":440803,
                  "坡头区":440804,
                  "麻章区":440811,
                  "遂溪县":440823,
                  "徐闻县":440825,
                  "廉江市":440881,
                  "雷州市":440882,
                  "吴川市":440883
              }
          },
          "云浮":{
              "id":4111,
              "区县":{
                  "云城区":445302,
                  "云安区":445303,
                  "新兴县":445321,
                  "郁南县":445322,
                  "罗定市":445381
              }
          },
          "中山":{
              "id":4112,
              "区县":{
                  "中山区":442000
              }
          },
          "珠海":{
              "id":4113,
              "区县":{
                  "香洲区":440402,
                  "斗门区":440403,
                  "金湾区":440404
              }
          },
          "肇庆":{
              "id":4114,
              "区县":{
                  "端州区":441202,
                  "鼎湖区":441203,
                  "高要区":441204,
                  "广宁县":441223,
                  "怀集县":441224,
                  "封开县":441225,
                  "德庆县":441226,
                  "四会市":441284
              }
          },
          "河源":{
              "id":4115,
              "区县":{
                  "源城区":441602,
                  "紫金县":441621,
                  "龙川县":441622,
                  "连平县":441623,
                  "和平县":441624,
                  "东源县":441625
              }
          },
          "东莞":{
              "id":4116,
              "区县":{
                  "东莞区":441900
              }
          },
          "惠州":{
              "id":4117,
              "区县":{
                  "惠城区":441302,
                  "惠阳区":441303,
                  "博罗县":441322,
                  "惠东县":441323,
                  "龙门县":441324
              }
          },
          "江门":{
              "id":4082,
              "区县":{
                  "蓬江区":440703,
                  "江海区":440704,
                  "新会区":440705,
                  "台山市":440781,
                  "开平市":440783,
                  "鹤山市":440784,
                  "恩平市":440785
              }
          },
          "揭阳":{
              "id":4083,
              "区县":{
                  "榕城区":445202,
                  "揭东区":445203,
                  "揭西县":445222,
                  "惠来县":445224,
                  "普宁市":445281
              }
          },
          "广州":{
              "id":4084,
              "区县":{
                  "荔湾区":440103,
                  "越秀区":440104,
                  "海珠区":440105,
                  "天河区":440106,
                  "白云区":440111,
                  "黄埔区":440112,
                  "番禺区":440113,
                  "花都区":440114,
                  "南沙区":440115,
                  "从化区":440117,
                  "增城区":440118
              }
          },
          "潮州":{
              "id":4085,
              "区县":{
                  "湘桥区":445102,
                  "潮安区":445103,
                  "饶平县":445122
              }
          },
          "茂名":{
              "id":4086,
              "区县":{
                  "茂南区":440902,
                  "电白区":440904,
                  "高州市":440981,
                  "化州市":440982,
                  "信宜市":440983
              }
          },
          "梅州":{
              "id":4088,
              "区县":{
                  "梅江区":441402,
                  "梅县区":441403,
                  "大埔县":441422,
                  "丰顺县":441423,
                  "五华县":441424,
                  "平远县":441426,
                  "蕉岭县":441427,
                  "兴宁市":441481
              }
          },
          "清远":{
              "id":4089,
              "区县":{
                  "清城区":441802,
                  "清新区":441803,
                  "佛冈县":441821,
                  "阳山县":441823,
                  "连山壮族瑶族自治县":441825,
                  "连南瑶族自治县":441826,
                  "英德市":441881,
                  "连州市":441882
              }
          },
          "佛山":{
              "id":4090,
              "区县":{
                  "禅城区":440604,
                  "南海区":440605,
                  "顺德区":440606,
                  "三水区":440607,
                  "高明区":440608
              }
          },
          "汕头":{
              "id":4091,
              "区县":{
                  "龙湖区":440507,
                  "金平区":440511,
                  "濠江区":440512,
                  "潮阳区":440513,
                  "潮南区":440514,
                  "澄海区":440515,
                  "南澳县":440523
              }
          },
          "汕尾":{
              "id":4092,
              "区县":{
                  "城区":441502,
                  "海丰县":441521,
                  "陆河县":441523,
                  "陆丰市":441581
              }
          },
          "深圳":{
              "id":4093,
              "区县":{
                  "罗湖区":440303,
                  "福田区":440304,
                  "南山区":440305,
                  "宝安区":440306,
                  "龙岗区":440307,
                  "盐田区":440308,
                  "龙华区":440309,
                  "坪山区":440310,
                  "光明区":440311
              }
          },
          "韶关":{
              "id":4094,
              "区县":{
                  "武江区":440203,
                  "浈江区":440204,
                  "曲江区":440205,
                  "始兴县":440222,
                  "仁化县":440224,
                  "翁源县":440229,
                  "乳源瑶族自治县":440232,
                  "新丰县":440233,
                  "乐昌市":440281,
                  "南雄市":440282
              }
          }
      }
  },
}

2、期待数据格式:

[
    {
        "id": 11,
        "level": 1,
        "name": "北京",
        "parent": 0,
        "children": [
            {
                "id": 110101,
                "level": 3,
                "name": "东城区",
                "parent": 11,
                "children": null,
                "full_name": "中国-北京-北京-东城"
            },
            {
                "id": 110102,
                "level": 3,
                "name": "西城区",
                "parent": 11,
                "children": null,
                "full_name": "中国-北京-北京-西城"
            },
            {
                "id": 110105,
                "level": 3,
                "name": "朝阳区",
                "parent": 11,
                "children": null,
                "full_name": "中国-北京-北京-朝阳"
            },
            {
                "id": 110106,
                "level": 3,
                "name": "丰台区",
                "parent": 11,
                "children": null,
                "full_name": "中国-北京-北京-丰台"
            },
            {
                "id": 110107,
                "level": 3,
                "name": "石景山区",
                "parent": 11,
                "children": null,
                "full_name": "中国-北京-北京-石景山"
            },
            {
                "id": 110108,
                "level": 3,
                "name": "海淀区",
                "parent": 11,
                "children": null,
                "full_name": "中国-北京-北京-海淀"
            },
            {
                "id": 110109,
                "level": 3,
                "name": "门头沟区",
                "parent": 11,
                "children": null,
                "full_name": "中国-北京-北京-门头沟"
            },
            {
                "id": 110111,
                "level": 3,
                "name": "房山区",
                "parent": 11,
                "children": null,
                "full_name": "中国-北京-北京-房山"
            },
            {
                "id": 110112,
                "level": 3,
                "name": "通州区",
                "parent": 11,
                "children": null,
                "full_name": "中国-北京-北京-通州"
            },
            {
                "id": 110113,
                "level": 3,
                "name": "顺义区",
                "parent": 11,
                "children": null,
                "full_name": "中国-北京-北京-顺义"
            },
            {
                "id": 110114,
                "level": 3,
                "name": "昌平区",
                "parent": 11,
                "children": null,
                "full_name": "中国-北京-北京-昌平"
            },
            {
                "id": 110115,
                "level": 3,
                "name": "大兴区",
                "parent": 11,
                "children": null,
                "full_name": "中国-北京-北京-大兴"
            },
            {
                "id": 110116,
                "level": 3,
                "name": "怀柔区",
                "parent": 11,
                "children": null,
                "full_name": "中国-北京-北京-怀柔"
            },
            {
                "id": 110117,
                "level": 3,
                "name": "平谷区",
                "parent": 11,
                "children": null,
                "full_name": "中国-北京-北京-平谷"
            },
            {
                "id": 110118,
                "level": 3,
                "name": "密云区",
                "parent": 11,
                "children": null,
                "full_name": "中国-北京-北京-密云"
            },
            {
                "id": 110119,
                "level": 3,
                "name": "延庆区",
                "parent": 11,
                "children": null,
                "full_name": "中国-北京-北京-延庆"
            }
        ],
        "full_name": "中国-北京"
    },
    {
        "id": 13,
        "level": 1,
        "name": "河北",
        "parent": 0,
        "children": [
            {
                "id": 1301,
                "level": 2,
                "name": "石家庄",
                "parent": 13,
                "children": [
                    {
                        "id": 130102,
                        "level": 3,
                        "name": "长安区",
                        "parent": 1301,
                        "children": null,
                        "full_name": "中国-河北-石家庄-长安"
                    },
                    {
                        "id": 130104,
                        "level": 3,
                        "name": "桥西区",
                        "parent": 1301,
                        "children": null,
                        "full_name": "中国-河北-石家庄-桥西"
                    },
                    {
                        "id": 130105,
                        "level": 3,
                        "name": "新华区",
                        "parent": 1301,
                        "children": null,
                        "full_name": "中国-河北-石家庄-新华"
                    },
                    {
                        "id": 130107,
                        "level": 3,
                        "name": "井陉矿区",
                        "parent": 1301,
                        "children": null,
                        "full_name": "中国-河北-石家庄-井陉矿"
                    },
                    {
                        "id": 130108,
                        "level": 3,
                        "name": "裕华区",
                        "parent": 1301,
                        "children": null,
                        "full_name": "中国-河北-石家庄-裕华"
                    },
                    {
                        "id": 130109,
                        "level": 3,
                        "name": "藁城区",
                        "parent": 1301,
                        "children": null,
                        "full_name": "中国-河北-石家庄-藁城"
                    },
                    {
                        "id": 130110,
                        "level": 3,
                        "name": "鹿泉区",
                        "parent": 1301,
                        "children": null,
                        "full_name": "中国-河北-石家庄-鹿泉"
                    },
                    {
                        "id": 130111,
                        "level": 3,
                        "name": "栾城区",
                        "parent": 1301,
                        "children": null,
                        "full_name": "中国-河北-石家庄-栾城"
                    },
                    {
                        "id": 130121,
                        "level": 3,
                        "name": "井陉县",
                        "parent": 1301,
                        "children": null,
                        "full_name": "中国-河北-石家庄-井陉"
                    },
                    {
                        "id": 130123,
                        "level": 3,
                        "name": "正定县",
                        "parent": 1301,
                        "children": null,
                        "full_name": "中国-河北-石家庄-正定"
                    },
                    {
                        "id": 130125,
                        "level": 3,
                        "name": "行唐县",
                        "parent": 1301,
                        "children": null,
                        "full_name": "中国-河北-石家庄-行唐"
                    },
                    {
                        "id": 130126,
                        "level": 3,
                        "name": "灵寿县",
                        "parent": 1301,
                        "children": null,
                        "full_name": "中国-河北-石家庄-灵寿"
                    },
                    {
                        "id": 130127,
                        "level": 3,
                        "name": "高邑县",
                        "parent": 1301,
                        "children": null,
                        "full_name": "中国-河北-石家庄-高邑"
                    },
                    {
                        "id": 130128,
                        "level": 3,
                        "name": "深泽县",
                        "parent": 1301,
                        "children": null,
                        "full_name": "中国-河北-石家庄-深泽"
                    },
                    {
                        "id": 130129,
                        "level": 3,
                        "name": "赞皇县",
                        "parent": 1301,
                        "children": null,
                        "full_name": "中国-河北-石家庄-赞皇"
                    },
                    {
                        "id": 130130,
                        "level": 3,
                        "name": "无极县",
                        "parent": 1301,
                        "children": null,
                        "full_name": "中国-河北-石家庄-无极"
                    },
                    {
                        "id": 130131,
                        "level": 3,
                        "name": "平山县",
                        "parent": 1301,
                        "children": null,
                        "full_name": "中国-河北-石家庄-平山"
                    },
                    {
                        "id": 130132,
                        "level": 3,
                        "name": "元氏县",
                        "parent": 1301,
                        "children": null,
                        "full_name": "中国-河北-石家庄-元氏"
                    },
                    {
                        "id": 130133,
                        "level": 3,
                        "name": "赵县",
                        "parent": 1301,
                        "children": null,
                        "full_name": "中国-河北-石家庄-赵县"
                    },
                    {
                        "id": 130181,
                        "level": 3,
                        "name": "辛集市",
                        "parent": 1301,
                        "children": null,
                        "full_name": "中国-河北-石家庄-辛集"
                    },
                    {
                        "id": 130183,
                        "level": 3,
                        "name": "晋州市",
                        "parent": 1301,
                        "children": null,
                        "full_name": "中国-河北-石家庄-晋州"
                    },
                    {
                        "id": 130184,
                        "level": 3,
                        "name": "新乐市",
                        "parent": 1301,
                        "children": null,
                        "full_name": "中国-河北-石家庄-新乐"
                    }
                ],
                "full_name": "中国-河北-石家庄"
            },
            {
                "id": 1302,
                "level": 2,
                "name": "唐山",
                "parent": 13,
                "children": [
                    {
                        "id": 130202,
                        "level": 3,
                        "name": "路南区",
                        "parent": 1302,
                        "children": null,
                        "full_name": "中国-河北-唐山-路南"
                    },
                    {
                        "id": 130203,
                        "level": 3,
                        "name": "路北区",
                        "parent": 1302,
                        "children": null,
                        "full_name": "中国-河北-唐山-路北"
                    },
                    {
                        "id": 130204,
                        "level": 3,
                        "name": "古冶区",
                        "parent": 1302,
                        "children": null,
                        "full_name": "中国-河北-唐山-古冶"
                    },
                    {
                        "id": 130205,
                        "level": 3,
                        "name": "开平区",
                        "parent": 1302,
                        "children": null,
                        "full_name": "中国-河北-唐山-开平"
                    },
                    {
                        "id": 130207,
                        "level": 3,
                        "name": "丰南区",
                        "parent": 1302,
                        "children": null,
                        "full_name": "中国-河北-唐山-丰南"
                    },
                    {
                        "id": 130208,
                        "level": 3,
                        "name": "丰润区",
                        "parent": 1302,
                        "children": null,
                        "full_name": "中国-河北-唐山-丰润区"
                    },
                    {
                        "id": 130209,
                        "level": 3,
                        "name": "曹妃甸区",
                        "parent": 1302,
                        "children": null,
                        "full_name": "中国-河北-唐山-曹妃甸"
                    },
                    {
                        "id": 130224,
                        "level": 3,
                        "name": "滦南县",
                        "parent": 1302,
                        "children": null,
                        "full_name": "中国-河北-唐山-滦南"
                    },
                    {
                        "id": 130225,
                        "level": 3,
                        "name": "乐亭县",
                        "parent": 1302,
                        "children": null,
                        "full_name": "中国-河北-唐山-乐亭"
                    },
                    {
                        "id": 130227,
                        "level": 3,
                        "name": "迁西县",
                        "parent": 1302,
                        "children": null,
                        "full_name": "中国-河北-唐山-迁西"
                    },
                    {
                        "id": 130229,
                        "level": 3,
                        "name": "玉田县",
                        "parent": 1302,
                        "children": null,
                        "full_name": "中国-河北-唐山-玉田"
                    },
                    {
                        "id": 130281,
                        "level": 3,
                        "name": "遵化市",
                        "parent": 1302,
                        "children": null,
                        "full_name": "中国-河北-唐山-遵化"
                    },
                    {
                        "id": 130283,
                        "level": 3,
                        "name": "迁安市",
                        "parent": 1302,
                        "children": null,
                        "full_name": "中国-河北-唐山-迁安"
                    },
                    {
                        "id": 130284,
                        "level": 3,
                        "name": "滦州市",
                        "parent": 1302,
                        "children": null,
                        "full_name": "中国-河北-唐山-滦州"
                    }
                ],
                "full_name": "中国-河北-唐山"
            },
            {
                "id": 1303,
                "level": 2,
                "name": "秦皇岛",
                "parent": 13,
                "children": [
                    {
                        "id": 130302,
                        "level": 3,
                        "name": "海港区",
                        "parent": 1303,
                        "children": null,
                        "full_name": "中国-河北-秦皇岛-海港"
                    },
                    {
                        "id": 130303,
                        "level": 3,
                        "name": "山海关区",
                        "parent": 1303,
                        "children": null,
                        "full_name": "中国-河北-秦皇岛-山海关"
                    },
                    {
                        "id": 130304,
                        "level": 3,
                        "name": "北戴河区",
                        "parent": 1303,
                        "children": null,
                        "full_name": "中国-河北-秦皇岛-北戴河"
                    },
                    {
                        "id": 130306,
                        "level": 3,
                        "name": "抚宁区",
                        "parent": 1303,
                        "children": null,
                        "full_name": "中国-河北-秦皇岛-抚宁"
                    },
                    {
                        "id": 130321,
                        "level": 3,
                        "name": "青龙满族自治县",
                        "parent": 1303,
                        "children": null,
                        "full_name": "中国-河北-秦皇岛-青龙"
                    },
                    {
                        "id": 130322,
                        "level": 3,
                        "name": "昌黎县",
                        "parent": 1303,
                        "children": null,
                        "full_name": "中国-河北-秦皇岛-昌黎"
                    },
                    {
                        "id": 130324,
                        "level": 3,
                        "name": "卢龙县",
                        "parent": 1303,
                        "children": null,
                        "full_name": "中国-河北-秦皇岛-卢龙"
                    }
                ],
                "full_name": "中国-河北-秦皇岛"
            },
            {
                "id": 1304,
                "level": 2,
                "name": "邯郸",
                "parent": 13,
                "children": [
                    {
                        "id": 130402,
                        "level": 3,
                        "name": "邯山区",
                        "parent": 1304,
                        "children": null,
                        "full_name": "中国-河北-邯郸-邯山"
                    },
                    {
                        "id": 130403,
                        "level": 3,
                        "name": "丛台区",
                        "parent": 1304,
                        "children": null,
                        "full_name": "中国-河北-邯郸-丛台"
                    },
                    {
                        "id": 130404,
                        "level": 3,
                        "name": "复兴区",
                        "parent": 1304,
                        "children": null,
                        "full_name": "中国-河北-邯郸-复兴"
                    },
                    {
                        "id": 130406,
                        "level": 3,
                        "name": "峰峰矿区",
                        "parent": 1304,
                        "children": null,
                        "full_name": "中国-河北-邯郸-峰峰矿"
                    },
                    {
                        "id": 130407,
                        "level": 3,
                        "name": "肥乡区",
                        "parent": 1304,
                        "children": null,
                        "full_name": "中国-河北-邯郸-肥乡"
                    },
                    {
                        "id": 130408,
                        "level": 3,
                        "name": "永年区",
                        "parent": 1304,
                        "children": null,
                        "full_name": "中国-河北-邯郸-永年"
                    },
                    {
                        "id": 130423,
                        "level": 3,
                        "name": "临漳县",
                        "parent": 1304,
                        "children": null,
                        "full_name": "中国-河北-邯郸-临漳"
                    },
                    {
                        "id": 130424,
                        "level": 3,
                        "name": "成安县",
                        "parent": 1304,
                        "children": null,
                        "full_name": "中国-河北-邯郸-成安"
                    },
                    {
                        "id": 130425,
                        "level": 3,
                        "name": "大名县",
                        "parent": 1304,
                        "children": null,
                        "full_name": "中国-河北-邯郸-大名"
                    },
                    {
                        "id": 130426,
                        "level": 3,
                        "name": "涉县",
                        "parent": 1304,
                        "children": null,
                        "full_name": "中国-河北-邯郸-涉县"
                    },
                    {
                        "id": 130427,
                        "level": 3,
                        "name": "磁县",
                        "parent": 1304,
                        "children": null,
                        "full_name": "中国-河北-邯郸-磁县"
                    },
                    {
                        "id": 130430,
                        "level": 3,
                        "name": "邱县",
                        "parent": 1304,
                        "children": null,
                        "full_name": "中国-河北-邯郸-邱县"
                    },
                    {
                        "id": 130431,
                        "level": 3,
                        "name": "鸡泽县",
                        "parent": 1304,
                        "children": null,
                        "full_name": "中国-河北-邯郸-鸡泽"
                    },
                    {
                        "id": 130432,
                        "level": 3,
                        "name": "广平县",
                        "parent": 1304,
                        "children": null,
                        "full_name": "中国-河北-邯郸-广平"
                    },
                    {
                        "id": 130433,
                        "level": 3,
                        "name": "馆陶县",
                        "parent": 1304,
                        "children": null,
                        "full_name": "中国-河北-邯郸-馆陶"
                    },
                    {
                        "id": 130434,
                        "level": 3,
                        "name": "魏县",
                        "parent": 1304,
                        "children": null,
                        "full_name": "中国-河北-邯郸-魏县"
                    },
                    {
                        "id": 130435,
                        "level": 3,
                        "name": "曲周县",
                        "parent": 1304,
                        "children": null,
                        "full_name": "中国-河北-邯郸-曲周"
                    },
                    {
                        "id": 130471,
                        "level": 3,
                        "name": "邯郸经济技术开发区",
                        "parent": 1304,
                        "children": null,
                        "full_name": "中国-河北-邯郸-邯郸经济技术开发区"
                    },
                    {
                        "id": 130481,
                        "level": 3,
                        "name": "武安市",
                        "parent": 1304,
                        "children": null,
                        "full_name": "中国-河北-邯郸-武安"
                    }
                ],
                "full_name": "中国-河北-邯郸"
            },
            {
                "id": 1305,
                "level": 2,
                "name": "邢台",
                "parent": 13,
                "children": [
                    {
                        "id": 130502,
                        "level": 3,
                        "name": "桥东区",
                        "parent": 1305,
                        "children": null,
                        "full_name": "中国-河北-邢台-桥东"
                    },
                    {
                        "id": 130503,
                        "level": 3,
                        "name": "桥西区",
                        "parent": 1305,
                        "children": null,
                        "full_name": "中国-河北-邢台-桥西"
                    },
                    {
                        "id": 130521,
                        "level": 3,
                        "name": "邢台县",
                        "parent": 1305,
                        "children": null,
                        "full_name": "中国-河北-邢台-邢台"
                    },
                    {
                        "id": 130522,
                        "level": 3,
                        "name": "临城县",
                        "parent": 1305,
                        "children": null,
                        "full_name": "中国-河北-邢台-临城"
                    },
                    {
                        "id": 130523,
                        "level": 3,
                        "name": "内丘县",
                        "parent": 1305,
                        "children": null,
                        "full_name": "中国-河北-邢台-内丘"
                    },
                    {
                        "id": 130524,
                        "level": 3,
                        "name": "柏乡县",
                        "parent": 1305,
                        "children": null,
                        "full_name": "中国-河北-邢台-柏乡"
                    },
                    {
                        "id": 130525,
                        "level": 3,
                        "name": "隆尧县",
                        "parent": 1305,
                        "children": null,
                        "full_name": "中国-河北-邢台-隆尧"
                    },
                    {
                        "id": 130526,
                        "level": 3,
                        "name": "任县",
                        "parent": 1305,
                        "children": null,
                        "full_name": "中国-河北-邢台-任县"
                    },
                    {
                        "id": 130527,
                        "level": 3,
                        "name": "南和县",
                        "parent": 1305,
                        "children": null,
                        "full_name": "中国-河北-邢台-南和"
                    },
                    {
                        "id": 130528,
                        "level": 3,
                        "name": "宁晋县",
                        "parent": 1305,
                        "children": null,
                        "full_name": "中国-河北-邢台-宁晋"
                    },
                    {
                        "id": 130529,
                        "level": 3,
                        "name": "巨鹿县",
                        "parent": 1305,
                        "children": null,
                        "full_name": "中国-河北-邢台-巨鹿"
                    },
                    {
                        "id": 130530,
                        "level": 3,
                        "name": "新河县",
                        "parent": 1305,
                        "children": null,
                        "full_name": "中国-河北-邢台-新河"
                    },
                    {
                        "id": 130531,
                        "level": 3,
                        "name": "广宗县",
                        "parent": 1305,
                        "children": null,
                        "full_name": "中国-河北-邢台-广宗"
                    },
                    {
                        "id": 130532,
                        "level": 3,
                        "name": "平乡县",
                        "parent": 1305,
                        "children": null,
                        "full_name": "中国-河北-邢台-平乡"
                    },
                    {
                        "id": 130533,
                        "level": 3,
                        "name": "威县",
                        "parent": 1305,
                        "children": null,
                        "full_name": "中国-河北-邢台-威县"
                    },
                    {
                        "id": 130534,
                        "level": 3,
                        "name": "清河县",
                        "parent": 1305,
                        "children": null,
                        "full_name": "中国-河北-邢台-清河"
                    },
                    {
                        "id": 130535,
                        "level": 3,
                        "name": "临西县",
                        "parent": 1305,
                        "children": null,
                        "full_name": "中国-河北-邢台-临西"
                    },
                    {
                        "id": 130581,
                        "level": 3,
                        "name": "南宫市",
                        "parent": 1305,
                        "children": null,
                        "full_name": "中国-河北-邢台-南宫"
                    },
                    {
                        "id": 130582,
                        "level": 3,
                        "name": "沙河市",
                        "parent": 1305,
                        "children": null,
                        "full_name": "中国-河北-邢台-沙河"
                    }
                ],
                "full_name": "中国-河北-邢台"
            },
            {
                "id": 1306,
                "level": 2,
                "name": "保定",
                "parent": 13,
                "children": [
                    {
                        "id": 130602,
                        "level": 3,
                        "name": "竞秀区",
                        "parent": 1306,
                        "children": null,
                        "full_name": "中国-河北-保定-竞秀"
                    },
                    {
                        "id": 130606,
                        "level": 3,
                        "name": "莲池区",
                        "parent": 1306,
                        "children": null,
                        "full_name": "中国-河北-保定-莲池"
                    },
                    {
                        "id": 130607,
                        "level": 3,
                        "name": "满城区",
                        "parent": 1306,
                        "children": null,
                        "full_name": "中国-河北-保定-满城"
                    },
                    {
                        "id": 130608,
                        "level": 3,
                        "name": "清苑区",
                        "parent": 1306,
                        "children": null,
                        "full_name": "中国-河北-保定-清苑"
                    },
                    {
                        "id": 130609,
                        "level": 3,
                        "name": "徐水区",
                        "parent": 1306,
                        "children": null,
                        "full_name": "中国-河北-保定-徐水"
                    },
                    {
                        "id": 130623,
                        "level": 3,
                        "name": "涞水县",
                        "parent": 1306,
                        "children": null,
                        "full_name": "中国-河北-保定-涞水"
                    },
                    {
                        "id": 130624,
                        "level": 3,
                        "name": "阜平县",
                        "parent": 1306,
                        "children": null,
                        "full_name": "中国-河北-保定-阜平"
                    },
                    {
                        "id": 130626,
                        "level": 3,
                        "name": "定兴县",
                        "parent": 1306,
                        "children": null,
                        "full_name": "中国-河北-保定-定兴"
                    },
                    {
                        "id": 130627,
                        "level": 3,
                        "name": "唐县",
                        "parent": 1306,
                        "children": null,
                        "full_name": "中国-河北-保定-唐县"
                    },
                    {
                        "id": 130628,
                        "level": 3,
                        "name": "高阳县",
                        "parent": 1306,
                        "children": null,
                        "full_name": "中国-河北-保定-高阳"
                    },
                    {
                        "id": 130629,
                        "level": 3,
                        "name": "容城县",
                        "parent": 1306,
                        "children": null,
                        "full_name": "中国-河北-保定-容城"
                    },
                    {
                        "id": 130630,
                        "level": 3,
                        "name": "涞源县",
                        "parent": 1306,
                        "children": null,
                        "full_name": "中国-河北-保定-涞源"
                    },
                    {
                        "id": 130631,
                        "level": 3,
                        "name": "望都县",
                        "parent": 1306,
                        "children": null,
                        "full_name": "中国-河北-保定-望都"
                    },
                    {
                        "id": 130632,
                        "level": 3,
                        "name": "安新县",
                        "parent": 1306,
                        "children": null,
                        "full_name": "中国-河北-保定-安新"
                    },
                    {
                        "id": 130633,
                        "level": 3,
                        "name": "易县",
                        "parent": 1306,
                        "children": null,
                        "full_name": "中国-河北-保定-易县"
                    },
                    {
                        "id": 130634,
                        "level": 3,
                        "name": "曲阳县",
                        "parent": 1306,
                        "children": null,
                        "full_name": "中国-河北-保定-曲阳"
                    },
                    {
                        "id": 130635,
                        "level": 3,
                        "name": "蠡县",
                        "parent": 1306,
                        "children": null,
                        "full_name": "中国-河北-保定-蠡县"
                    },
                    {
                        "id": 130636,
                        "level": 3,
                        "name": "顺平县",
                        "parent": 1306,
                        "children": null,
                        "full_name": "中国-河北-保定-顺平"
                    },
                    {
                        "id": 130637,
                        "level": 3,
                        "name": "博野县",
                        "parent": 1306,
                        "children": null,
                        "full_name": "中国-河北-保定-博野"
                    },
                    {
                        "id": 130638,
                        "level": 3,
                        "name": "雄县",
                        "parent": 1306,
                        "children": null,
                        "full_name": "中国-河北-保定-雄县"
                    },
                    {
                        "id": 130681,
                        "level": 3,
                        "name": "涿州市",
                        "parent": 1306,
                        "children": null,
                        "full_name": "中国-河北-保定-涿州"
                    },
                    {
                        "id": 130682,
                        "level": 3,
                        "name": "定州市",
                        "parent": 1306,
                        "children": null,
                        "full_name": "中国-河北-保定-定州"
                    },
                    {
                        "id": 130683,
                        "level": 3,
                        "name": "安国市",
                        "parent": 1306,
                        "children": null,
                        "full_name": "中国-河北-保定-安国"
                    },
                    {
                        "id": 130684,
                        "level": 3,
                        "name": "高碑店市",
                        "parent": 1306,
                        "children": null,
                        "full_name": "中国-河北-保定-高碑店"
                    }
                ],
                "full_name": "中国-河北-保定"
            },
            {
                "id": 1307,
                "level": 2,
                "name": "张家口",
                "parent": 13,
                "children": [
                    {
                        "id": 130702,
                        "level": 3,
                        "name": "桥东区",
                        "parent": 1307,
                        "children": null,
                        "full_name": "中国-河北-张家口-桥东"
                    },
                    {
                        "id": 130703,
                        "level": 3,
                        "name": "桥西区",
                        "parent": 1307,
                        "children": null,
                        "full_name": "中国-河北-张家口-桥西"
                    },
                    {
                        "id": 130705,
                        "level": 3,
                        "name": "宣化区",
                        "parent": 1307,
                        "children": null,
                        "full_name": "中国-河北-张家口-宣化"
                    },
                    {
                        "id": 130706,
                        "level": 3,
                        "name": "下花园区",
                        "parent": 1307,
                        "children": null,
                        "full_name": "中国-河北-张家口-下花园"
                    },
                    {
                        "id": 130708,
                        "level": 3,
                        "name": "万全区",
                        "parent": 1307,
                        "children": null,
                        "full_name": "中国-河北-张家口-万全"
                    },
                    {
                        "id": 130709,
                        "level": 3,
                        "name": "崇礼区",
                        "parent": 1307,
                        "children": null,
                        "full_name": "中国-河北-张家口-崇礼"
                    },
                    {
                        "id": 130722,
                        "level": 3,
                        "name": "张北县",
                        "parent": 1307,
                        "children": null,
                        "full_name": "中国-河北-张家口-张北"
                    },
                    {
                        "id": 130723,
                        "level": 3,
                        "name": "康保县",
                        "parent": 1307,
                        "children": null,
                        "full_name": "中国-河北-张家口-康保"
                    },
                    {
                        "id": 130724,
                        "level": 3,
                        "name": "沽源县",
                        "parent": 1307,
                        "children": null,
                        "full_name": "中国-河北-张家口-沽源"
                    },
                    {
                        "id": 130725,
                        "level": 3,
                        "name": "尚义县",
                        "parent": 1307,
                        "children": null,
                        "full_name": "中国-河北-张家口-尚义"
                    },
                    {
                        "id": 130726,
                        "level": 3,
                        "name": "蔚县",
                        "parent": 1307,
                        "children": null,
                        "full_name": "中国-河北-张家口-蔚县"
                    },
                    {
                        "id": 130727,
                        "level": 3,
                        "name": "阳原县",
                        "parent": 1307,
                        "children": null,
                        "full_name": "中国-河北-张家口-阳原"
                    },
                    {
                        "id": 130728,
                        "level": 3,
                        "name": "怀安县",
                        "parent": 1307,
                        "children": null,
                        "full_name": "中国-河北-张家口-怀安"
                    },
                    {
                        "id": 130730,
                        "level": 3,
                        "name": "怀来县",
                        "parent": 1307,
                        "children": null,
                        "full_name": "中国-河北-张家口-怀来"
                    },
                    {
                        "id": 130731,
                        "level": 3,
                        "name": "涿鹿县",
                        "parent": 1307,
                        "children": null,
                        "full_name": "中国-河北-张家口-涿鹿"
                    },
                    {
                        "id": 130732,
                        "level": 3,
                        "name": "赤城县",
                        "parent": 1307,
                        "children": null,
                        "full_name": "中国-河北-张家口-赤城"
                    }
                ],
                "full_name": "中国-河北-张家口"
            },
            {
                "id": 1308,
                "level": 2,
                "name": "承德",
                "parent": 13,
                "children": [
                    {
                        "id": 130802,
                        "level": 3,
                        "name": "双桥区",
                        "parent": 1308,
                        "children": null,
                        "full_name": "中国-河北-承德-双桥"
                    },
                    {
                        "id": 130803,
                        "level": 3,
                        "name": "双滦区",
                        "parent": 1308,
                        "children": null,
                        "full_name": "中国-河北-承德-双滦"
                    },
                    {
                        "id": 130804,
                        "level": 3,
                        "name": "鹰手营子矿区",
                        "parent": 1308,
                        "children": null,
                        "full_name": "中国-河北-承德-鹰手营子矿"
                    },
                    {
                        "id": 130821,
                        "level": 3,
                        "name": "承德县",
                        "parent": 1308,
                        "children": null,
                        "full_name": "中国-河北-承德-承德"
                    },
                    {
                        "id": 130822,
                        "level": 3,
                        "name": "兴隆县",
                        "parent": 1308,
                        "children": null,
                        "full_name": "中国-河北-承德-兴隆"
                    },
                    {
                        "id": 130824,
                        "level": 3,
                        "name": "滦平县",
                        "parent": 1308,
                        "children": null,
                        "full_name": "中国-河北-承德-滦平"
                    },
                    {
                        "id": 130825,
                        "level": 3,
                        "name": "隆化县",
                        "parent": 1308,
                        "children": null,
                        "full_name": "中国-河北-承德-隆化"
                    },
                    {
                        "id": 130826,
                        "level": 3,
                        "name": "丰宁满族自治县",
                        "parent": 1308,
                        "children": null,
                        "full_name": "中国-河北-承德-丰宁"
                    },
                    {
                        "id": 130827,
                        "level": 3,
                        "name": "宽城满族自治县",
                        "parent": 1308,
                        "children": null,
                        "full_name": "中国-河北-承德-宽城"
                    },
                    {
                        "id": 130828,
                        "level": 3,
                        "name": "围场满族蒙古族自治县",
                        "parent": 1308,
                        "children": null,
                        "full_name": "中国-河北-承德-围场"
                    },
                    {
                        "id": 130881,
                        "level": 3,
                        "name": "平泉市",
                        "parent": 1308,
                        "children": null,
                        "full_name": "中国-河北-承德-平泉"
                    }
                ],
                "full_name": "中国-河北-承德"
            },
            {
                "id": 1309,
                "level": 2,
                "name": "沧州",
                "parent": 13,
                "children": [
                    {
                        "id": 130902,
                        "level": 3,
                        "name": "新华区",
                        "parent": 1309,
                        "children": null,
                        "full_name": "中国-河北-沧州-新华"
                    },
                    {
                        "id": 130903,
                        "level": 3,
                        "name": "运河区",
                        "parent": 1309,
                        "children": null,
                        "full_name": "中国-河北-沧州-运河"
                    },
                    {
                        "id": 130921,
                        "level": 3,
                        "name": "沧县",
                        "parent": 1309,
                        "children": null,
                        "full_name": "中国-河北-沧州-沧县"
                    },
                    {
                        "id": 130922,
                        "level": 3,
                        "name": "青县",
                        "parent": 1309,
                        "children": null,
                        "full_name": "中国-河北-沧州-青县"
                    },
                    {
                        "id": 130923,
                        "level": 3,
                        "name": "东光县",
                        "parent": 1309,
                        "children": null,
                        "full_name": "中国-河北-沧州-东光"
                    },
                    {
                        "id": 130924,
                        "level": 3,
                        "name": "海兴县",
                        "parent": 1309,
                        "children": null,
                        "full_name": "中国-河北-沧州-海兴"
                    },
                    {
                        "id": 130925,
                        "level": 3,
                        "name": "盐山县",
                        "parent": 1309,
                        "children": null,
                        "full_name": "中国-河北-沧州-盐山"
                    },
                    {
                        "id": 130926,
                        "level": 3,
                        "name": "肃宁县",
                        "parent": 1309,
                        "children": null,
                        "full_name": "中国-河北-沧州-肃宁"
                    },
                    {
                        "id": 130927,
                        "level": 3,
                        "name": "南皮县",
                        "parent": 1309,
                        "children": null,
                        "full_name": "中国-河北-沧州-南皮"
                    },
                    {
                        "id": 130928,
                        "level": 3,
                        "name": "吴桥县",
                        "parent": 1309,
                        "children": null,
                        "full_name": "中国-河北-沧州-吴桥"
                    },
                    {
                        "id": 130929,
                        "level": 3,
                        "name": "献县",
                        "parent": 1309,
                        "children": null,
                        "full_name": "中国-河北-沧州-献县"
                    },
                    {
                        "id": 130930,
                        "level": 3,
                        "name": "孟村回族自治县",
                        "parent": 1309,
                        "children": null,
                        "full_name": "中国-河北-沧州-孟村"
                    },
                    {
                        "id": 130981,
                        "level": 3,
                        "name": "泊头市",
                        "parent": 1309,
                        "children": null,
                        "full_name": "中国-河北-沧州-泊头"
                    },
                    {
                        "id": 130982,
                        "level": 3,
                        "name": "任丘市",
                        "parent": 1309,
                        "children": null,
                        "full_name": "中国-河北-沧州-任丘"
                    },
                    {
                        "id": 130983,
                        "level": 3,
                        "name": "黄骅市",
                        "parent": 1309,
                        "children": null,
                        "full_name": "中国-河北-沧州-黄骅"
                    },
                    {
                        "id": 130984,
                        "level": 3,
                        "name": "河间市",
                        "parent": 1309,
                        "children": null,
                        "full_name": "中国-河北-沧州-河间"
                    }
                ],
                "full_name": "中国-河北-沧州"
            },
            {
                "id": 1310,
                "level": 2,
                "name": "廊坊",
                "parent": 13,
                "children": [
                    {
                        "id": 131002,
                        "level": 3,
                        "name": "安次区",
                        "parent": 1310,
                        "children": null,
                        "full_name": "中国-河北-廊坊-安次"
                    },
                    {
                        "id": 131003,
                        "level": 3,
                        "name": "广阳区",
                        "parent": 1310,
                        "children": null,
                        "full_name": "中国-河北-廊坊-广阳"
                    },
                    {
                        "id": 131022,
                        "level": 3,
                        "name": "固安县",
                        "parent": 1310,
                        "children": null,
                        "full_name": "中国-河北-廊坊-固安"
                    },
                    {
                        "id": 131023,
                        "level": 3,
                        "name": "永清县",
                        "parent": 1310,
                        "children": null,
                        "full_name": "中国-河北-廊坊-永清"
                    },
                    {
                        "id": 131024,
                        "level": 3,
                        "name": "香河县",
                        "parent": 1310,
                        "children": null,
                        "full_name": "中国-河北-廊坊-香河"
                    },
                    {
                        "id": 131025,
                        "level": 3,
                        "name": "大城县",
                        "parent": 1310,
                        "children": null,
                        "full_name": "中国-河北-廊坊-大城"
                    },
                    {
                        "id": 131026,
                        "level": 3,
                        "name": "文安县",
                        "parent": 1310,
                        "children": null,
                        "full_name": "中国-河北-廊坊-文安"
                    },
                    {
                        "id": 131028,
                        "level": 3,
                        "name": "大厂回族自治县",
                        "parent": 1310,
                        "children": null,
                        "full_name": "中国-河北-廊坊-大厂"
                    },
                    {
                        "id": 131081,
                        "level": 3,
                        "name": "霸州市",
                        "parent": 1310,
                        "children": null,
                        "full_name": "中国-河北-廊坊-霸州"
                    },
                    {
                        "id": 131082,
                        "level": 3,
                        "name": "三河市",
                        "parent": 1310,
                        "children": null,
                        "full_name": "中国-河北-廊坊-三河"
                    }
                ],
                "full_name": "中国-河北-廊坊"
            },
            {
                "id": 1311,
                "level": 2,
                "name": "衡水",
                "parent": 13,
                "children": [
                    {
                        "id": 131102,
                        "level": 3,
                        "name": "桃城区",
                        "parent": 1311,
                        "children": null,
                        "full_name": "中国-河北-衡水-桃城"
                    },
                    {
                        "id": 131103,
                        "level": 3,
                        "name": "冀州区",
                        "parent": 1311,
                        "children": null,
                        "full_name": "中国-河北-衡水-冀州"
                    },
                    {
                        "id": 131121,
                        "level": 3,
                        "name": "枣强县",
                        "parent": 1311,
                        "children": null,
                        "full_name": "中国-河北-衡水-枣强"
                    },
                    {
                        "id": 131122,
                        "level": 3,
                        "name": "武邑县",
                        "parent": 1311,
                        "children": null,
                        "full_name": "中国-河北-衡水-武邑"
                    },
                    {
                        "id": 131123,
                        "level": 3,
                        "name": "武强县",
                        "parent": 1311,
                        "children": null,
                        "full_name": "中国-河北-衡水-武强"
                    },
                    {
                        "id": 131124,
                        "level": 3,
                        "name": "饶阳县",
                        "parent": 1311,
                        "children": null,
                        "full_name": "中国-河北-衡水-饶阳"
                    },
                    {
                        "id": 131125,
                        "level": 3,
                        "name": "安平县",
                        "parent": 1311,
                        "children": null,
                        "full_name": "中国-河北-衡水-安平"
                    },
                    {
                        "id": 131126,
                        "level": 3,
                        "name": "故城县",
                        "parent": 1311,
                        "children": null,
                        "full_name": "中国-河北-衡水-故城"
                    },
                    {
                        "id": 131127,
                        "level": 3,
                        "name": "景县",
                        "parent": 1311,
                        "children": null,
                        "full_name": "中国-河北-衡水-景县"
                    },
                    {
                        "id": 131128,
                        "level": 3,
                        "name": "阜城县",
                        "parent": 1311,
                        "children": null,
                        "full_name": "中国-河北-衡水-阜城"
                    },
                    {
                        "id": 131182,
                        "level": 3,
                        "name": "深州市",
                        "parent": 1311,
                        "children": null,
                        "full_name": "中国-河北-衡水-深州"
                    }
                ],
                "full_name": "中国-河北-衡水"
            }
        ],
        "full_name": "中国-河北"
    }
]

level, full_name字段可以没有。主要是转成这种嵌套树形结构 ,最顶层parent 为0

阅读 2.6k
4 个回答

下列代码可格式化 百度省市三级地域代码

function format(data, parent = 0) {
    return data && Object.entries(data).map(([key, val]) => ({
        id: val?.id ?? val,
        name: key,
        parent,
        children: format(val['市'] ?? val['区县'], val.id)
    })) || null
}

const formatted_data = format(data);

@JenK 我在这回复吧,评论里贴不了表格,也贴不了图片,怪难受的。。


感谢大佬的耐心回复。还是有个疑问:

为啥不用些诸如 SQLite 的数据库,替代 json 存储 和 js 查询呢?

昨天,我测试了下,用 SQLite 来实现大佬的【地址智能识别】库功能(主要是识别省/市/区/街/村,目前支持逐级模糊匹配),并利用 sql.js 在浏览器端测试(硬件:i5-8250U 笔记本)。结果:

行政区划层级数数据条数查询 7 个平均 39 字 4~5 级地址总耗时数据库大小gzip 后zstd 后
5 级66182440 毫秒16.8 MB5.72 MB4.32 MB
4 级449185 毫秒880 KB409 KB330 KB

而且内存占用几乎就是【数据库大小】本身(那个 pcasCode.js 加载完好像就要 20 MB 内存了,这内存可以加载完整的 5 级数据库了都。。)

感觉 SQLite 各方面都很强啊,无论是体积、速度、内存占用、还是代码量(这个功能就一条 SELECT 语句,大概几十行而已)


这图片压缩,压得我人都麻了。。关键缩放压缩完,比我原图(110 KB)还大。。😂

补个放大的图:

今天正好看到一篇文章是讲解讲数组转为树形结构的

const obj2tree = (obj, parentId = "0") => {
  if (!obj) {
    return null;
  }
  const result = [];

  for (let key in obj) {
    const item = obj[key];
    const isObj = typeof item === "object";

    const child = {
      id: isObj ? item.id : item,
      name: key,
      parentId,
      children: isObj ? obj2tree(item["市"] || item["区县"], item.id) : null,
    };
    result.push(child);
  }

  return result;
};

我这里实现的,并没有把中间的东城去掉。

image.png

参考: 如何将数据从扁平数组结构转为树形结构

新手上路,请多包涵

我一直用的是这个地址库的数据中华人民共和国行政区划(五级)


1.【省市区联动选择】,理论上不用依赖后端,那 regions.json / regions.db / 或其他适合的格式,需要满足什么条件,才适合放到前端,真的脱离后端呢?
2.gzip 后 30 KB(怎么界定这个数值呢?)
3.不要让前端干这活儿(为啥呀?)

这是我在项目中前端引入的地址数据,完整的数据是2MB,gzip后是403KB,加载时间506ms,时间上还是可以接受的(没有cdn、没有开启http2)
image.png

  1. 数据的话格式一般是推荐js或者json,js的话用模块导出,或者挂载到windows.导入json可以参考import-json-file-in-js

    目前我们有自己的前端中台服务,可以把一些静态资源放在这里以接口的形式返回,也方便修改数据,和打包到代码内文件还是有点差别
  2. gzip后数据量很大的话,需要进行弱网络测试,如果这方面要求不高,这个数据也不是立即使用的话,可以放在后台静默加载初始化。
  3. 后端来说可以提供数据的按需加载,也方便去修改某些值(前端如果没有数据中台的话需要重新发布代码).如果数据一直不变,且数据量小,可以考虑放在前端
  4. 我觉得这都不是问题,各端在于多沟通,权衡好利弊,放在哪里都行
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏