{"id":2294,"date":"2024-11-10T13:40:22","date_gmt":"2024-11-10T05:40:22","guid":{"rendered":"https:\/\/fwq.ai\/blog\/2294\/"},"modified":"2024-11-10T13:40:22","modified_gmt":"2024-11-10T05:40:22","slug":"%e5%a6%82%e4%bd%95%e5%b0%86%e5%b8%a6%e6%9c%89%e7%9c%81%e7%ba%a7%e3%80%81%e5%b8%82%e7%ba%a7%e3%80%81%e5%8c%ba%e7%ba%a7%e4%bf%a1%e6%81%af%e7%9a%84%e6%a0%91%e5%bd%a2%e7%bb%93%e6%9e%84%ef%bc%8c%e8%bd%ac","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/2294\/","title":{"rendered":"\u5982\u4f55\u5c06\u5e26\u6709\u7701\u7ea7\u3001\u5e02\u7ea7\u3001\u533a\u7ea7\u4fe1\u606f\u7684\u6811\u5f62\u7ed3\u6784\uff0c\u8f6c\u6362\u4e3a\u6241\u5e73\u5316\u7684\u4ee3\u7801\u6570\u7ec4\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173070864328128.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5c06\u5e26\u6709\u7701\u7ea7\u3001\u5e02\u7ea7\u3001\u533a\u7ea7\u4fe1\u606f\u7684\u6811\u5f62\u7ed3\u6784\uff0c\u8f6c\u6362\u4e3a\u6241\u5e73\u5316\u7684\u4ee3\u7801\u6570\u7ec4\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5c06\u5e26\u6709\u7701\u7ea7\u3001\u5e02\u7ea7\u3001\u533a\u7ea7\u4fe1\u606f\u7684\u6811\u5f62\u7ed3\u6784\uff0c\u8f6c\u6362\u4e3a\u6241\u5e73\u5316\u7684\u4ee3\u7801\u6570\u7ec4\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u7701\u5e02\u533a\u6811\u7ed3\u6784\u6241\u5e73\u5316\u8f6c\u6362<\/strong><\/p>\n<p>\u5982\u4f55\u5c06\u5e26\u6709\u7701\u7ea7\u3001\u5e02\u7ea7\u3001\u533a\u7ea7\u4fe1\u606f\u7684\u6811\u5f62\u7ed3\u6784\uff0c\u8f6c\u6362\u4e3a\u6241\u5e73\u5316\u7684\u4ee3\u7801\u6570\u7ec4\uff1f<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p>\u91c7\u7528\u9012\u5f52\u7684\u65b9\u6cd5\uff0c\u5c06\u9009\u4e2d\u7684\u72b6\u6001\u4f20\u9012\u4e0b\u53bb\uff1a<\/p>\n<pre>\/**\n * \u83b7\u53d6\u6240\u6709\u88ab\u9009\u4e2d\u7684code\n * @param {any[]} list \u6811\u5f62\u7ed3\u6784\n * @param {string[]} parentList \u5230\u7236\u7ea7\u6240\u6709\u7684code\u7684\u6570\u7ec4\n * @param {boolean} parentChecked \u4e0a\u7ea7\u662f\u5426\u88ab\u9009\u4e2d\uff0c\u82e5\u4e0a\u7ea7\u88ab\u9009\u4e2d\uff0c\u5219\u4e0b\u9762\u6240\u6709\u7684\u5b50\u9009\u9879\u5747\u662f\u88ab\u9009\u4e2d\u7684\u6570\u636e\n *\/\nconst getCheckedList = (list, parentList = [], parentChecked = false) =&gt; {\n  let result = [];\n\n  if (!Array.isArray(list)) {\n    return result;\n  }\n\n  list.forEach((item) =&gt; {\n    const checked = parentChecked || item.check; \/\/ \u7236\u7ea7\u88ab\u9009\u4e2d\u6216\u5f53\u524d\u88ab\u9009\u4e2d\uff0c\u5747\u8ba4\u4e3a\u662f\u88ab\u9009\u4e2d\n    const codeList = parentList.concat(item.code);\n\n    if (item.children) {\n      \/\/ \u5f53\u524d\u4e0d\u662f\u6700\u5185\u5c42\n      result = result.concat(getCheckedList(item.children, codeList, checked));\n    } else {\n      \/\/ \u5df2\u5230\u6700\u5185\u5c42\n      if (checked) {\n        result.push(codeList);\n      }\n    }\n  });\n\n  return result;\n};<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u4f7f\u7528\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>console.log(getCheckedList(tree));<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u7ed3\u679c\uff1a<\/strong><\/p>\n<pre>[\n  [110000, 110100, 110101],\n  [110000, 110100, 110102],\n  [130000, 130100, 130102],\n  [130000, 130100, 130104],\n  [150000, 150100, 150103]\n]<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5c06\u5e26\u6709\u7701\u7ea7\u3001\u5e02\u7ea7\u3001\u533a\u7ea7\u4fe1\u606f\u7684\u6811\u5f62\u7ed3\u6784\uff0c\u8f6c\u6362\u4e3a\u6241\u5e73\u5316\u7684\u4ee3\u7801\u6570\u7ec4\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 \u5982\u4f55\u5c06\u5e26\u6709\u7701\u7ea7\u3001\u5e02\u7ea7\u3001\u533a\u7ea7\u4fe1\u606f\u7684\u6811\u5f62\u7ed3\u6784\uff0c\u8f6c\u6362\u4e3a\u6241\u5e73\u5316\u7684\u4ee3\u7801\u6570\u7ec4\uff1f \u89e3\u51b3\u65b9\u6848\uff1a \u91c7\u7528\u9012\u5f52\u7684\u65b9\u6cd5\uff0c\u5c06\u9009\u4e2d\u7684\u72b6\u6001\u4f20\u9012\u4e0b\u53bb\uff1a \/** * \u83b7\u53d6\u6240\u6709\u88ab\u9009\u4e2d\u7684code * @param {any[]} list \u6811\u5f62\u7ed3\u6784 * @param {string[]} parentList \u5230\u7236\u7ea7\u6240\u6709\u7684code\u7684\u6570\u7ec4 * @param {boolean} parentChecked \u4e0a\u7ea7\u662f\u5426\u88ab\u9009\u4e2d\uff0c\u82e5\u4e0a\u7ea7\u88ab\u9009\u4e2d\uff0c\u5219\u4e0b\u9762\u6240\u6709\u7684\u5b50\u9009\u9879\u5747\u662f\u88ab\u9009\u4e2d\u7684\u6570\u636e *\/ const getCheckedList = (list, parentList = [], parentChecked = false) =&gt; { let result = []; if (!Array.isArray(list)) { return result; } list.forEach((item) =&gt; { const checked = parentChecked || item.check; \/\/ [&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-2294","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2294","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=2294"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2294\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=2294"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=2294"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=2294"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}