<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                >[success] # 小的案例 ~~~ 1.現有api返回數據[ {province:'?東省',city:'?州市',district:'天河區'}, {province:'?東省',city:'?州市',district:'?云區'}, {province:'?東省',city:'東莞市',district:'常平鎮'}] 請問如何在最短時間內處理成[{ name: '?東省', children: [ { name: '?州 市', children: [{name: '天河區'},{name:'?云區'}] }, { name: '東莞市', children: [{name: '常平鎮'}] }, ]}] ~~~ >[danger] ##### 不完善的解決方案 ~~~ 1.下面代碼不太完善只是完成了思路,整個代碼用了組合和工廠模式實現 ~~~ ~~~ class Root{ constructor(name){ this.name = name this.children = [] this.parent = null } add(file){ file.parent = this this.children.push(file) } } class DistrictLeaf{ constructor(name){ this.name = name this.parent = null } add(file){ throw new Error( '區下面不能添加' ); } } class Factory{ obj = {} creat(name){ if(this.obj[name]){ return this.obj[name] }else{ return this.obj[name] = new Root(name) } } } let ccc = [ {province:'?東省',city:'?州市',district:'天河區'}, {province:'?東省',city:'?州市',district:'?云區'}, {province:'?東省',city:'東莞市',district:'常平鎮'}] // const provinceRoot = new Root('?東省') const provinceRoot = new Factory() const districtRoot = new Factory() ccc.forEach(item =>{ const province = provinceRoot.creat(item.province) const district = new DistrictLeaf(item.district) if(!Reflect.has(districtRoot.obj,item.city)){ const city = districtRoot.creat(item.city) province.add(city) city.add(district) } }) console.log(provinceRoot.obj) ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看