{"id":25871,"date":"2024-11-24T14:55:03","date_gmt":"2024-11-24T06:55:03","guid":{"rendered":"https:\/\/fwq.ai\/blog\/25871\/"},"modified":"2024-11-24T14:55:03","modified_gmt":"2024-11-24T06:55:03","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%e8%bd%ac%e6%8d%a2%e6%88%90%e6%89%81%e5%b9%b3%e5%8c%96%e7%bb%93%e6%9e%84%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/25871\/","title":{"rendered":"\u5982\u4f55\u5c06\u7701\u5e02\u533a\u6811\u5f62\u7ed3\u6784\u8f6c\u6362\u6210\u6241\u5e73\u5316\u7ed3\u6784\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173071966465655.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5c06\u7701\u5e02\u533a\u6811\u5f62\u7ed3\u6784\u8f6c\u6362\u6210\u6241\u5e73\u5316\u7ed3\u6784\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5c06\u7701\u5e02\u533a\u6811\u5f62\u7ed3\u6784\u8f6c\u6362\u6210\u6241\u5e73\u5316\u7ed3\u6784\uff1f\u63d2\u56fe\" \/><\/p>\n<p>\u5982\u4f55\u5c06\u7701\u5e02\u533a\u6811\u5f62\u7ed3\u6784\u8f6c\u6362\u6210\u6241\u5e73\u5316\u7ed3\u6784\uff1f<\/p>\n<p>\u6211\u4eec\u6709\u4e00\u4e2a\u6811\u5f62\u6570\u636e\u7ed3\u6784\uff0c\u8868\u793a\u7701\u5e02\u533a\u4e4b\u95f4\u7684\u5173\u7cfb\uff0c\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>\u6bcf\u4e2a\u8282\u70b9\u4ee3\u8868\u4e00\u4e2a\u884c\u653f\u533a\u57df\u3002<\/li>\n<li>\u5982\u679c\u4e00\u4e2a\u8282\u70b9\u6709\u5b50\u8282\u70b9\uff0c\u5219\u8868\u793a\u8be5\u884c\u653f\u533a\u57df\u4e0b\u6709\u4e0b\u7ea7\u884c\u653f\u533a\u57df\u3002<\/li>\n<li>\u5982\u679c\u4e00\u4e2a\u8282\u70b9\u6ca1\u6709\u5b50\u8282\u70b9\uff0c\u5219\u8868\u793a\u8be5\u884c\u653f\u533a\u57df\u4e3a\u6700\u5e95\u5c42\u884c\u653f\u533a\u57df\u3002<\/li>\n<\/ul>\n<p>\u73b0\u5728\uff0c\u6211\u4eec\u9700\u8981\u5c06\u8fd9\u4e2a\u6811\u5f62\u7ed3\u6784\u8f6c\u6362\u6210\u6241\u5e73\u5316\u7ed3\u6784\u3002\u6241\u5e73\u5316\u7ed3\u6784\u662f\u4e00\u4e2a\u6570\u7ec4\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5143\u7d20\u90fd\u662f\u4e00\u4e2a\u5bf9\u8c61\uff0c\u5305\u542b\u4ee5\u4e0b\u5b57\u6bb5\uff1a<\/p>\n<ul>\n<li>provinceAreald\uff1a\u7701\u7ea7\u884c\u653f\u533a\u57df\u7684\u4ee3\u7801\u3002<\/li>\n<li>cityAreald\uff1a\u5e02\u7ea7\u884c\u653f\u533a\u57df\u7684\u4ee3\u7801\u3002\u5982\u679c\u8be5\u884c\u653f\u533a\u57df\u4e3a\u7701\u7ea7\uff0c\u5219\u4e3a null\u3002<\/li>\n<li>countryAreald\uff1a\u533a\u7ea7\u884c\u653f\u533a\u57df\u7684\u4ee3\u7801\u3002\u5982\u679c\u8be5\u884c\u653f\u533a\u57df\u4e3a\u7701\u7ea7\u6216\u5e02\u7ea7\uff0c\u5219\u4e3a null\u3002<\/li>\n<li>actualAreaLevel\uff1a\u5b9e\u9645\u7684\u884c\u653f\u7ea7\u522b\u30021\u8868\u793a\u7701\u7ea7\uff0c2\u8868\u793a\u5e02\u7ea7\uff0c3\u8868\u793a\u533a\u7ea7\u3002<\/li>\n<\/ul>\n<p>\u8f6c\u6362\u89c4\u5219\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>\u5982\u679c\u4e00\u4e2a\u884c\u653f\u533a\u57df\u7684\u6240\u6709\u4e0b\u7ea7\u884c\u653f\u533a\u57df\u90fd\u88ab\u9009\u4e2d\uff0c\u5219\u8be5\u884c\u653f\u533a\u57df\u7684\u5e02\u53bf\u7ea7\u884c\u653f\u533a\u57df\u4ee3\u7801\u548c\u5b9e\u9645\u884c\u653f\u7ea7\u522b\u90fd\u4e3a null\u3002<\/li>\n<li>\u5982\u679c\u4e00\u4e2a\u884c\u653f\u533a\u57df\u7684\u90e8\u5206\u4e0b\u7ea7\u884c\u653f\u533a\u57df\u88ab\u9009\u4e2d\uff0c\u5219\u8be5\u884c\u653f\u533a\u57df\u7684\u6240\u6709\u4e0b\u7ea7\u884c\u653f\u533a\u57df\u7684\u4ee3\u7801\u548c\u5b9e\u9645\u884c\u653f\u7ea7\u522b\u90fd\u5305\u542b\u5728\u7ed3\u679c\u4e2d\u3002<\/li>\n<\/ul>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u5c06\u6811\u5f62\u7ed3\u6784\u8f6c\u6362\u6210\u6241\u5e73\u5316\u7ed3\u6784\u7684 JavaScript \u51fd\u6570\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>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5c06\u7701\u5e02\u533a\u6811\u5f62\u7ed3\u6784\u8f6c\u6362\u6210\u6241\u5e73\u5316\u7ed3\u6784\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>\u5982\u4f55\u5c06\u7701\u5e02\u533a\u6811\u5f62\u7ed3\u6784\u8f6c\u6362\u6210\u6241\u5e73\u5316\u7ed3\u6784\uff1f \u6211\u4eec\u6709\u4e00\u4e2a\u6811\u5f62\u6570\u636e\u7ed3\u6784\uff0c\u8868\u793a\u7701\u5e02\u533a\u4e4b\u95f4\u7684\u5173\u7cfb\uff0c\u5176\u4e2d\uff1a \u6bcf\u4e2a\u8282\u70b9\u4ee3\u8868\u4e00\u4e2a\u884c\u653f\u533a\u57df\u3002 \u5982\u679c\u4e00\u4e2a\u8282\u70b9\u6709\u5b50\u8282\u70b9\uff0c\u5219\u8868\u793a\u8be5\u884c\u653f\u533a\u57df\u4e0b\u6709\u4e0b\u7ea7\u884c\u653f\u533a\u57df\u3002 \u5982\u679c\u4e00\u4e2a\u8282\u70b9\u6ca1\u6709\u5b50\u8282\u70b9\uff0c\u5219\u8868\u793a\u8be5\u884c\u653f\u533a\u57df\u4e3a\u6700\u5e95\u5c42\u884c\u653f\u533a\u57df\u3002 \u73b0\u5728\uff0c\u6211\u4eec\u9700\u8981\u5c06\u8fd9\u4e2a\u6811\u5f62\u7ed3\u6784\u8f6c\u6362\u6210\u6241\u5e73\u5316\u7ed3\u6784\u3002\u6241\u5e73\u5316\u7ed3\u6784\u662f\u4e00\u4e2a\u6570\u7ec4\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5143\u7d20\u90fd\u662f\u4e00\u4e2a\u5bf9\u8c61\uff0c\u5305\u542b\u4ee5\u4e0b\u5b57\u6bb5\uff1a provinceAreald\uff1a\u7701\u7ea7\u884c\u653f\u533a\u57df\u7684\u4ee3\u7801\u3002 cityAreald\uff1a\u5e02\u7ea7\u884c\u653f\u533a\u57df\u7684\u4ee3\u7801\u3002\u5982\u679c\u8be5\u884c\u653f\u533a\u57df\u4e3a\u7701\u7ea7\uff0c\u5219\u4e3a null\u3002 countryAreald\uff1a\u533a\u7ea7\u884c\u653f\u533a\u57df\u7684\u4ee3\u7801\u3002\u5982\u679c\u8be5\u884c\u653f\u533a\u57df\u4e3a\u7701\u7ea7\u6216\u5e02\u7ea7\uff0c\u5219\u4e3a null\u3002 actualAreaLevel\uff1a\u5b9e\u9645\u7684\u884c\u653f\u7ea7\u522b\u30021\u8868\u793a\u7701\u7ea7\uff0c2\u8868\u793a\u5e02\u7ea7\uff0c3\u8868\u793a\u533a\u7ea7\u3002 \u8f6c\u6362\u89c4\u5219\u5982\u4e0b\uff1a \u5982\u679c\u4e00\u4e2a\u884c\u653f\u533a\u57df\u7684\u6240\u6709\u4e0b\u7ea7\u884c\u653f\u533a\u57df\u90fd\u88ab\u9009\u4e2d\uff0c\u5219\u8be5\u884c\u653f\u533a\u57df\u7684\u5e02\u53bf\u7ea7\u884c\u653f\u533a\u57df\u4ee3\u7801\u548c\u5b9e\u9645\u884c\u653f\u7ea7\u522b\u90fd\u4e3a null\u3002 \u5982\u679c\u4e00\u4e2a\u884c\u653f\u533a\u57df\u7684\u90e8\u5206\u4e0b\u7ea7\u884c\u653f\u533a\u57df\u88ab\u9009\u4e2d\uff0c\u5219\u8be5\u884c\u653f\u533a\u57df\u7684\u6240\u6709\u4e0b\u7ea7\u884c\u653f\u533a\u57df\u7684\u4ee3\u7801\u548c\u5b9e\u9645\u884c\u653f\u7ea7\u522b\u90fd\u5305\u542b\u5728\u7ed3\u679c\u4e2d\u3002 \u4e0b\u9762\u662f\u4e00\u4e2a\u5c06\u6811\u5f62\u7ed3\u6784\u8f6c\u6362\u6210\u6241\u5e73\u5316\u7ed3\u6784\u7684 JavaScript \u51fd\u6570\uff1a 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 = [&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-25871","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25871","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=25871"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25871\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=25871"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=25871"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=25871"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}