{"id":2288,"date":"2024-11-10T16:17:40","date_gmt":"2024-11-10T08:17:40","guid":{"rendered":"https:\/\/fwq.ai\/blog\/2288\/"},"modified":"2024-11-10T16:17:40","modified_gmt":"2024-11-10T08:17:40","slug":"%e5%a6%82%e4%bd%95%e5%b0%86%e7%9c%81%e5%b8%82%e5%8c%ba%e6%a0%91%e5%bd%a2%e7%bb%93%e6%9e%84%e6%89%81%e5%b9%b3%e5%8c%96%e5%b9%b6%e6%a0%b9%e6%8d%ae%e5%8c%ba%e5%9f%9f%e9%80%89%e4%b8%ad%e6%83%85%e5%86%b5","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/2288\/","title":{"rendered":"\u5982\u4f55\u5c06\u7701\u5e02\u533a\u6811\u5f62\u7ed3\u6784\u6241\u5e73\u5316\u5e76\u6839\u636e\u533a\u57df\u9009\u4e2d\u60c5\u51b5\u83b7\u53d6\u5bf9\u5e94\u4ee3\u7801\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173070721873829.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5c06\u7701\u5e02\u533a\u6811\u5f62\u7ed3\u6784\u6241\u5e73\u5316\u5e76\u6839\u636e\u533a\u57df\u9009\u4e2d\u60c5\u51b5\u83b7\u53d6\u5bf9\u5e94\u4ee3\u7801\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5c06\u7701\u5e02\u533a\u6811\u5f62\u7ed3\u6784\u6241\u5e73\u5316\u5e76\u6839\u636e\u533a\u57df\u9009\u4e2d\u60c5\u51b5\u83b7\u53d6\u5bf9\u5e94\u4ee3\u7801\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u4ee5\u6811\u5f62\u7ed3\u6784\u5b9e\u73b0\u7701\u5e02\u533a\u6241\u5e73\u5316<\/strong><\/p>\n<p>\u5728\u6570\u636e\u7ed3\u6784\u4e2d\uff0c\u7701\u5e02\u533a\u901a\u5e38\u4ee5\u6811\u5f62\u7ed3\u6784\u5448\u73b0\uff0c\u4f46\u6709\u65f6\u9700\u8981\u5c06\u5176\u6241\u5e73\u5316\u4e3a\u4e00\u7ea7\u4e8c\u7ea7\u4e09\u7ea7\u4ee3\u7801\u7684\u7ed3\u6784\u3002<\/p>\n<p><strong>\u95ee\u9898\u63cf\u8ff0<\/strong><\/p>\n<p>\u7ed9\u5b9a\u7701\u5e02\u533a\u6811\u5f62\u6570\u636e\uff0c\u5176\u4e2d\u8282\u70b9\u5e26\u6709\u5df2\u9009\u4e2d\u7684\u6807\u8bb0\uff1a\u201cchecked\u201d\u3002\u8981\u6c42\u5c06\u6811\u5f62\u7ed3\u6784\u6241\u5e73\u5316\u4e3a\uff1a<\/p>\n<ul>\n<li>\u5982\u679c\u4e09\u7ea7\u533a\u57df\u5747\u5df2\u9009\u4e2d\uff0c\u5219\u4ec5\u83b7\u53d6\u4e00\u7ea7\u548c\u4e8c\u7ea7\u533a\u57df\u4ee3\u7801\uff0c\u4e09\u7ea7\u533a\u57df\u4ee3\u7801\u4e3a null\u3002<\/li>\n<li>\u5982\u679c\u4e8c\u7ea7\u533a\u57df\u5747\u5df2\u9009\u4e2d\uff0c\u5219\u4ec5\u83b7\u53d6\u4e00\u7ea7\u533a\u57df\u4ee3\u7801\uff0c\u4e8c\u7ea7\u548c\u4e09\u7ea7\u533a\u57df\u4ee3\u7801\u4e3a null\u3002<\/li>\n<li>\u5982\u679c\u4e09\u7ea7\u9009\u4e2d\u90e8\u5206\u533a\u57df\uff0c\u5219\u83b7\u53d6\u4e00\u7ea7\uff0c\u4e8c\u7ea7\u548c\u4e09\u7ea7\u533a\u57df\u4ee3\u7801\u3002<\/li>\n<\/ul>\n<p><strong>\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u4ee5\u4e0b JavaScript \u4ee3\u7801\u5b9e\u73b0\u4e86\u8fd9\u4e00\u8f6c\u6362\uff1a<\/p>\n<pre>function getNewData(data) {\n  let d = []\n\n  for (let province of data) {\n    if (province.checked == 1) {\n      let obj = {\n        provinceAreald: province.code,\n        cityAreald: null,\n        countryAreald: null,\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}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u8f85\u52a9\u51fd\u6570\u8bf4\u660e<\/strong><\/p>\n<ul>\n<li>cityCheck\uff1a\u68c0\u67e5\u67d0\u4e2a\u7701\u7684\u5e02\u7ea7\u5b50\u8282\u70b9\u9009\u4e2d\u60c5\u51b5\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a\u6241\u5e73\u5316\u7684\u6570\u7ec4\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5143\u7d20\u5305\u542b\u7701\u7ea7\u3001\u5e02\u7ea7\u548c\u53bf\u7ea7\u4ee3\u7801\u3002<\/li>\n<li>countryCheck\uff1a\u68c0\u67e5\u67d0\u4e2a\u5e02\u7684\u53bf\u7ea7\u5b50\u8282\u70b9\u9009\u4e2d\u60c5\u51b5\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a\u6241\u5e73\u5316\u7684\u6570\u7ec4\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5143\u7d20\u5305\u542b\u7701\u7ea7\u3001\u5e02\u7ea7\u548c\u53bf\u7ea7\u4ee3\u7801\u3002<\/li>\n<\/ul>\n<p><strong>\u4ee3\u7801\u8bf4\u660e<\/strong><\/p>\n<ol>\n<li>getNewData \u51fd\u6570\u904d\u5386\u4e00\u7ea7\u533a\u57df\uff0c\u5982\u679c\u4e00\u7ea7\u533a\u57df\u88ab\u9009\u4e2d\uff0c\u5219\u521d\u59cb\u5316\u4e00\u4e2a\u5bf9\u8c61 obj \u8868\u793a\u4e00\u7ea7\u533a\u57df\u4fe1\u606f\u3002<\/li>\n<li>cityCheck \u51fd\u6570\u904d\u5386\u4e8c\u7ea7\u533a\u57df\uff0c\u5982\u679c\u4e8c\u7ea7\u533a\u57df\u88ab\u9009\u4e2d\uff0c\u5219\u66f4\u65b0 obj \u5bf9\u8c61\u7684\u4e8c\u7ea7\u533a\u57df\u4fe1\u606f\u3002<\/li>\n<li>countryCheck \u51fd\u6570\u904d\u5386\u4e09\u7ea7\u533a\u57df\uff0c\u5982\u679c\u4e09\u7ea7\u533a\u57df\u88ab\u9009\u4e2d\uff0c\u5219\u5c06\u4e09\u7ea7\u533a\u57df\u4fe1\u606f\u6dfb\u52a0\u5230 obj \u5bf9\u8c61\u4e2d\u3002<\/li>\n<li>\u6839\u636e\u4e8c\u7ea7\u533a\u57df\u548c\u4e09\u7ea7\u533a\u57df\u7684\u9009\u4e2d\u60c5\u51b5\uff0c\u66f4\u65b0 obj \u5bf9\u8c61\u7684 cityAreald\u3001countryAreald \u548c actualAreaLevel \u5c5e\u6027\u3002<\/li>\n<li>\u5c06\u5904\u7406\u540e\u7684 obj \u5bf9\u8c61\u6dfb\u52a0\u5230\u7ed3\u679c\u6570\u7ec4 d \u4e2d\u3002<\/li>\n<\/ol>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5c06\u7701\u5e02\u533a\u6811\u5f62\u7ed3\u6784\u6241\u5e73\u5316\u5e76\u6839\u636e\u533a\u57df\u9009\u4e2d\u60c5\u51b5\u83b7\u53d6\u5bf9\u5e94\u4ee3\u7801\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>\u4ee5\u6811\u5f62\u7ed3\u6784\u5b9e\u73b0\u7701\u5e02\u533a\u6241\u5e73\u5316 \u5728\u6570\u636e\u7ed3\u6784\u4e2d\uff0c\u7701\u5e02\u533a\u901a\u5e38\u4ee5\u6811\u5f62\u7ed3\u6784\u5448\u73b0\uff0c\u4f46\u6709\u65f6\u9700\u8981\u5c06\u5176\u6241\u5e73\u5316\u4e3a\u4e00\u7ea7\u4e8c\u7ea7\u4e09\u7ea7\u4ee3\u7801\u7684\u7ed3\u6784\u3002 \u95ee\u9898\u63cf\u8ff0 \u7ed9\u5b9a\u7701\u5e02\u533a\u6811\u5f62\u6570\u636e\uff0c\u5176\u4e2d\u8282\u70b9\u5e26\u6709\u5df2\u9009\u4e2d\u7684\u6807\u8bb0\uff1a\u201cchecked\u201d\u3002\u8981\u6c42\u5c06\u6811\u5f62\u7ed3\u6784\u6241\u5e73\u5316\u4e3a\uff1a \u5982\u679c\u4e09\u7ea7\u533a\u57df\u5747\u5df2\u9009\u4e2d\uff0c\u5219\u4ec5\u83b7\u53d6\u4e00\u7ea7\u548c\u4e8c\u7ea7\u533a\u57df\u4ee3\u7801\uff0c\u4e09\u7ea7\u533a\u57df\u4ee3\u7801\u4e3a null\u3002 \u5982\u679c\u4e8c\u7ea7\u533a\u57df\u5747\u5df2\u9009\u4e2d\uff0c\u5219\u4ec5\u83b7\u53d6\u4e00\u7ea7\u533a\u57df\u4ee3\u7801\uff0c\u4e8c\u7ea7\u548c\u4e09\u7ea7\u533a\u57df\u4ee3\u7801\u4e3a null\u3002 \u5982\u679c\u4e09\u7ea7\u9009\u4e2d\u90e8\u5206\u533a\u57df\uff0c\u5219\u83b7\u53d6\u4e00\u7ea7\uff0c\u4e8c\u7ea7\u548c\u4e09\u7ea7\u533a\u57df\u4ee3\u7801\u3002 \u89e3\u51b3\u65b9\u6848 \u4ee5\u4e0b JavaScript \u4ee3\u7801\u5b9e\u73b0\u4e86\u8fd9\u4e00\u8f6c\u6362\uff1a function getNewData(data) { let d = [] for (let province of data) { if (province.checked == 1) { let obj = { provinceAreald: province.code, cityAreald: null, countryAreald: null, actualAreaLevel: &#8216;1&#8217; } const cityArr = cityCheck(province, obj, d) if (cityArr.length == province.children.length) { [&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-2288","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2288","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=2288"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2288\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=2288"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=2288"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=2288"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}