{"id":25748,"date":"2024-11-24T13:58:13","date_gmt":"2024-11-24T05:58:13","guid":{"rendered":"https:\/\/fwq.ai\/blog\/25748\/"},"modified":"2024-11-24T13:58:13","modified_gmt":"2024-11-24T05:58:13","slug":"%e5%a6%82%e4%bd%95%e5%b0%86%e5%b5%8c%e5%a5%97%e7%9a%84%e7%9c%81%e5%b8%82%e5%8c%ba%e6%a0%91%e7%bb%93%e6%9e%84%e6%89%81%e5%b9%b3%e5%8c%96%e4%b8%ba%e6%8c%87%e5%ae%9a%e6%a0%bc%e5%bc%8f%ef%bc%8c%e4%bb%a5-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/25748\/","title":{"rendered":"\u5982\u4f55\u5c06\u5d4c\u5957\u7684\u7701\u5e02\u533a\u6811\u7ed3\u6784\u6241\u5e73\u5316\u4e3a\u6307\u5b9a\u683c\u5f0f\uff0c\u4ee5\u6ee1\u8db3\u4e0d\u540c\u9009\u62e9\u7684\u5730\u5740\u83b7\u53d6\u9700\u6c42\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173069518451504.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5c06\u5d4c\u5957\u7684\u7701\u5e02\u533a\u6811\u7ed3\u6784\u6241\u5e73\u5316\u4e3a\u6307\u5b9a\u683c\u5f0f\uff0c\u4ee5\u6ee1\u8db3\u4e0d\u540c\u9009\u62e9\u7684\u5730\u5740\u83b7\u53d6\u9700\u6c42\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5c06\u5d4c\u5957\u7684\u7701\u5e02\u533a\u6811\u7ed3\u6784\u6241\u5e73\u5316\u4e3a\u6307\u5b9a\u683c\u5f0f\uff0c\u4ee5\u6ee1\u8db3\u4e0d\u540c\u9009\u62e9\u7684\u5730\u5740\u83b7\u53d6\u9700\u6c42\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u7701\u5e02\u533a\u6811\u7ed3\u6784\u6241\u5e73\u5316\u8f6c\u6362\u7ed3\u6784<\/strong><\/p>\n<p>\u672c\u6587\u65e8\u5728\u89e3\u51b3\u5982\u4f55\u5c06\u5d4c\u5957\u7684\u7701\u5e02\u533a\u7ed3\u6784\u6811\u6241\u5e73\u5316\u4e3a\u6307\u5b9a\u683c\u5f0f\u7684\u7ed3\u6784\uff0c\u4ee5\u6ee1\u8db3\u7279\u5b9a\u9700\u6c42\u3002<\/p>\n<p><strong>\u9700\u6c42\uff1a<\/strong><\/p>\n<ul>\n<li>\u5982\u679c\u4e09\u7ea7\u5730\u5740\u90fd\u9009\u4e2d\u4e86\uff0c\u53ea\u83b7\u53d6\u4e00\u7ea7\u548c\u4e8c\u7ea7\u5730\u5740\u3002<\/li>\n<li>\u5982\u679c\u4e8c\u7ea7\u5730\u5740\u90fd\u9009\u4e2d\u4e86\uff0c\u53ea\u83b7\u53d6\u4e00\u7ea7\u5730\u5740\u3002<\/li>\n<li>\u5982\u679c\u4e09\u7ea7\u5730\u5740\u9009\u4e2d\u4e86\u67d0\u4e9b\uff0c\u83b7\u53d6\u4e00\u7ea7\u3001\u4e8c\u7ea7\u548c\u4e09\u7ea7\u5730\u5740\u3002<\/li>\n<\/ul>\n<p><strong>\u6570\u636e\u7ed3\u6784\uff1a<\/strong><\/p>\n<p>\u6811\u5f62\u7ed3\u6784\u7684\u6570\u636e\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<pre>[\n  {\n    \"code\": \"110000\",\n    \"value\": \"\u5317\u4eac\u5e02\",\n    \"checked\": \"1\",\n    \"children\": [\n      {\n        \"code\": \"110100\",\n        \"value\": \"\u5317\u4eac\u5e02\",\n        \"checked\": \"1\",\n        \"children\": [\n          {\n            \"code\": \"110101\",\n            \"value\": \"\u4e1c\u57ce\u533a\",\n            \"checked\": \"1\"\n          },\n          {\n            \"code\": \"110102\",\n            \"value\": \"\u897f\u57ce\u533a\",\n            \"checked\": \"1\"\n          }\n        ]\n      }\n    ]\n  },\n  {\n    \"code\": \"120000\",\n    \"value\": \"\u5929\u6d25\u5e02\",\n    \"checked\": \"1\",\n    \"children\": [\n      {\n        \"code\": \"120100\",\n        \"value\": \"\u5929\u6d25\u5e02\",\n        \"checked\": \"1\",\n        \"children\": [\n          {\n            \"code\": \"120101\",\n            \"value\": \"\u548c\u5e73\u533a\",\n            \"checked\": \"0\"\n          },\n          {\n            \"code\": \"120102\",\n            \"value\": \"\u6cb3\u4e1c\u533a\",\n            \"checked\": \"1\"\n          }\n        ]\n      }\n    ]\n  }\n]<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u6241\u5e73\u5316\u5904\u7406\uff1a<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u6241\u5e73\u5316\u5904\u7406\u7684 JavaScript \u4ee3\u7801\uff1a<\/p>\n<pre>function getNewData(data) {\n  let d = []\n\n  for (let province of data) {\n\n    if (province.checked == 1) {\n      let obj = {\n        provinceAreald: province.code,\n        cityAreald: null,  \/\/\u59822\u7ea7\u5168\u90e8\u9009\u4e2d\u4e3anull\n        countryAreald: null,  \/\/\u59823\u7ea7\u5168\u90e8\u9009\u4e2d\u4e3anull\n        actualAreaLevel:'1'\n      }\n\n      const cityArr = cityCheck(province, obj, d)\n\n      if (cityArr.length == province.children.length) {\n        Object.assign(obj, {\n          cityAreald: null,\n          actualAreaLevel: '1',\n        })\n        d.push(obj)  \/\/ 2\u7ea7\u83dc\u5355\u88ab&lt;\u5168\u90e8&gt;\u9009\u4e2d\n      } else {\n        d.push(...cityArr)  \/\/ 2\u7ea7\u83dc\u5355\u88ab&lt;\u90e8\u5206&gt;\u9009\u4e2d\n      }\n\n    }\n  }\n\n\n  function cityCheck(province, obj, d) {\n\n    let cityArr = []\n    for (let city of province.children) {\n\n      if (city.checked == 1) {\n        Object.assign(obj, {\n          cityAreald: city.code,\n          actualAreaLevel: '2',\n        })\n\n        \/\/ \u53c2\u6570obj, d\u53ef\u80fd\u88ab\u6539\u53d8\n        const countryArr = countryCheck(city, obj, d)\n\n        if (countryArr.length == city.children.length) {\n          Object.assign(obj, {\n            countryAreald: null,\n            actualAreaLevel: '2',\n          })\n          cityArr.push(obj)  \/\/ 3\u7ea7\u83dc\u5355\u88ab&lt;\u5168\u90e8&gt;\u9009\u4e2d\n        } else {\n          d = d.push(...countryArr)  \/\/ 3\u7ea7\u83dc\u5355\u88ab&lt;\u90e8\u5206&gt;\u9009\u4e2d\n        }\n\n      }\n\n    }\n    return cityArr\n\n  }\n\n\n  function countryCheck(city, obj, d) {\n\n    let countryArr = []\n    for (let country of city.children) {\n\n      if (country.checked == 1) {\n        countryArr.push(\n          Object.assign(obj, {\n            countryAreald: country.code,\n            actualAreaLevel: '3',\n          })\n        )\n      }\n\n    }\n    return countryArr\n  }\n\n\n  return d\n}\n\nconst newData = getNewData(data)\nconsole.log(newData)<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u6241\u5e73\u5316\u7ed3\u679c\uff1a<\/strong><\/p>\n<pre>[\n  {\n    provinceAreald : '110000',\n    cityAreald: null,  \/\/\u59822\u7ea7\u5168\u90e8\u9009\u4e2d\u4e3anull\n    countryAreald: null,  \/\/\u59823\u7ea7\u5168\u90e8\u9009\u4e2d\u4e3anull\n    actualAreaLevel:'1'\n  },\n  {\n    provinceAreald : '120000',\n    cityAreald: '120100',  \/\/\u59822\u7ea7\u5168\u90e8\u9009\u4e2d\u4e3anull\n    countryAreald: '120102',  \/\/\u59823\u7ea7\u5168\u90e8\u9009\u4e2d\u4e3anull\n    actualAreaLevel:'3' \/\/\u5c42\u7ea7\n  }\n]<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5c06\u5d4c\u5957\u7684\u7701\u5e02\u533a\u6811\u7ed3\u6784\u6241\u5e73\u5316\u4e3a\u6307\u5b9a\u683c\u5f0f\uff0c\u4ee5\u6ee1\u8db3\u4e0d\u540c\u9009\u62e9\u7684\u5730\u5740\u83b7\u53d6\u9700\u6c42\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7701\u5e02\u533a\u6811\u7ed3\u6784\u6241\u5e73\u5316\u8f6c\u6362\u7ed3\u6784 \u672c\u6587\u65e8\u5728\u89e3\u51b3\u5982\u4f55\u5c06\u5d4c\u5957\u7684\u7701\u5e02\u533a\u7ed3\u6784\u6811\u6241\u5e73\u5316\u4e3a\u6307\u5b9a\u683c\u5f0f\u7684\u7ed3\u6784\uff0c\u4ee5\u6ee1\u8db3\u7279\u5b9a\u9700\u6c42\u3002 \u9700\u6c42\uff1a \u5982\u679c\u4e09\u7ea7\u5730\u5740\u90fd\u9009\u4e2d\u4e86\uff0c\u53ea\u83b7\u53d6\u4e00\u7ea7\u548c\u4e8c\u7ea7\u5730\u5740\u3002 \u5982\u679c\u4e8c\u7ea7\u5730\u5740\u90fd\u9009\u4e2d\u4e86\uff0c\u53ea\u83b7\u53d6\u4e00\u7ea7\u5730\u5740\u3002 \u5982\u679c\u4e09\u7ea7\u5730\u5740\u9009\u4e2d\u4e86\u67d0\u4e9b\uff0c\u83b7\u53d6\u4e00\u7ea7\u3001\u4e8c\u7ea7\u548c\u4e09\u7ea7\u5730\u5740\u3002 \u6570\u636e\u7ed3\u6784\uff1a \u6811\u5f62\u7ed3\u6784\u7684\u6570\u636e\u793a\u4f8b\u5982\u4e0b\uff1a [ { &#8220;code&#8221;: &#8220;110000&#8221;, &#8220;value&#8221;: &#8220;\u5317\u4eac\u5e02&#8221;, &#8220;checked&#8221;: &#8220;1&#8221;, &#8220;children&#8221;: [ { &#8220;code&#8221;: &#8220;110100&#8221;, &#8220;value&#8221;: &#8220;\u5317\u4eac\u5e02&#8221;, &#8220;checked&#8221;: &#8220;1&#8221;, &#8220;children&#8221;: [ { &#8220;code&#8221;: &#8220;110101&#8221;, &#8220;value&#8221;: &#8220;\u4e1c\u57ce\u533a&#8221;, &#8220;checked&#8221;: &#8220;1&#8221; }, { &#8220;code&#8221;: &#8220;110102&#8221;, &#8220;value&#8221;: &#8220;\u897f\u57ce\u533a&#8221;, &#8220;checked&#8221;: &#8220;1&#8221; } ] } ] }, { &#8220;code&#8221;: &#8220;120000&#8221;, &#8220;value&#8221;: &#8220;\u5929\u6d25\u5e02&#8221;, &#8220;checked&#8221;: &#8220;1&#8221;, &#8220;children&#8221;: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-25748","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25748","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=25748"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25748\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=25748"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=25748"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=25748"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}