{"id":25802,"date":"2024-11-24T14:58:08","date_gmt":"2024-11-24T06:58:08","guid":{"rendered":"https:\/\/fwq.ai\/blog\/25802\/"},"modified":"2024-11-24T14:58:08","modified_gmt":"2024-11-24T06:58:08","slug":"%e5%a6%82%e4%bd%95%e5%b0%86%e7%9c%81%e5%b8%82%e5%8c%ba%e6%a0%91%e7%bb%93%e6%9e%84%e6%95%b0%e6%8d%ae%e6%89%81%e5%b9%b3%e5%8c%96%e8%bd%ac%e6%8d%a2%ef%bc%8c%e4%bb%a5%e4%be%bf%e6%bb%a1%e8%b6%b3%e7%89%b9-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/25802\/","title":{"rendered":"\u5982\u4f55\u5c06\u7701\u5e02\u533a\u6811\u7ed3\u6784\u6570\u636e\u6241\u5e73\u5316\u8f6c\u6362\uff0c\u4ee5\u4fbf\u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6\u4e0b\u7684\u7b5b\u9009\u8981\u6c42\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173070721572092.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5c06\u7701\u5e02\u533a\u6811\u7ed3\u6784\u6570\u636e\u6241\u5e73\u5316\u8f6c\u6362\uff0c\u4ee5\u4fbf\u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6\u4e0b\u7684\u7b5b\u9009\u8981\u6c42\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5c06\u7701\u5e02\u533a\u6811\u7ed3\u6784\u6570\u636e\u6241\u5e73\u5316\u8f6c\u6362\uff0c\u4ee5\u4fbf\u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6\u4e0b\u7684\u7b5b\u9009\u8981\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>\u7ed9\u5b9a\u4e00\u68f5\u8868\u793a\u7701\u5e02\u533a\u7684\u6811\u7ed3\u6784\u6570\u636e\uff0c\u9700\u8981\u5c06\u5176\u6241\u5e73\u5316\u8f6c\u6362\uff0c\u4ee5\u6ee1\u8db3\u5982\u4e0b\u8981\u6c42\uff1a<\/p>\n<ul>\n<li>\u5982\u679c3\u7ea7\u90fd\u9009\u4e2d\u4e86\uff0c\u90a3\u5c31\u53ea\u83b7\u53d61\u7ea7\u548c2\u7ea7\u3002<\/li>\n<li>\u5982\u679c2\u7ea7\u90fd\u9009\u4e2d\u4e86\uff0c\u53ea\u83b7\u53d61\u7ea7\u3002<\/li>\n<li>\u59823\u7ea7\u9009\u4e2d\u67d0\u51e0\u4e2a\uff0c\u83b7\u53d61\uff0c2\uff0c3\u7ea7\u3002<\/li>\n<\/ul>\n<p><strong>\u89e3\u51b3\u65b9\u6848<\/strong><\/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>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5c06\u7701\u5e02\u533a\u6811\u7ed3\u6784\u6570\u636e\u6241\u5e73\u5316\u8f6c\u6362\uff0c\u4ee5\u4fbf\u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6\u4e0b\u7684\u7b5b\u9009\u8981\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 \u7ed9\u5b9a\u4e00\u68f5\u8868\u793a\u7701\u5e02\u533a\u7684\u6811\u7ed3\u6784\u6570\u636e\uff0c\u9700\u8981\u5c06\u5176\u6241\u5e73\u5316\u8f6c\u6362\uff0c\u4ee5\u6ee1\u8db3\u5982\u4e0b\u8981\u6c42\uff1a \u5982\u679c3\u7ea7\u90fd\u9009\u4e2d\u4e86\uff0c\u90a3\u5c31\u53ea\u83b7\u53d61\u7ea7\u548c2\u7ea7\u3002 \u5982\u679c2\u7ea7\u90fd\u9009\u4e2d\u4e86\uff0c\u53ea\u83b7\u53d61\u7ea7\u3002 \u59823\u7ea7\u9009\u4e2d\u67d0\u51e0\u4e2a\uff0c\u83b7\u53d61\uff0c2\uff0c3\u7ea7\u3002 \u89e3\u51b3\u65b9\u6848 function getNewData(data) { let d = [] for (let province of data) { if (province.checked == 1) { let obj = { provinceAreald: province.code, cityAreald: null, \/\/ \u59822\u7ea7\u5168\u90e8\u9009\u4e2d\u4e3anull countryAreald: null, \/\/ \u59823\u7ea7\u5168\u90e8\u9009\u4e2d\u4e3anull actualAreaLevel: &#8216;1&#8217;, } const cityArr = cityCheck(province, obj, d) if (cityArr.length == province.children.length) { Object.assign(obj, { cityAreald: [&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-25802","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25802","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=25802"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25802\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=25802"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=25802"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=25802"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}