{"id":53131,"date":"2024-12-03T14:35:11","date_gmt":"2024-12-03T06:35:11","guid":{"rendered":"https:\/\/fwq.ai\/blog\/53131\/"},"modified":"2024-12-03T14:35:11","modified_gmt":"2024-12-03T06:35:11","slug":"%e5%a6%82%e4%bd%95%e9%80%9a%e8%bf%87%e9%80%92%e5%bd%92%e7%ae%97%e6%b3%95%e6%8f%90%e5%8f%96%e8%b7%a8%e7%ba%a7%e9%80%89%e4%b8%ad%e7%9a%84%e8%8a%82%e7%82%b9%e4%bb%a3%e7%a0%81%ef%bc%9f-3","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/53131\/","title":{"rendered":"\u5982\u4f55\u901a\u8fc7\u9012\u5f52\u7b97\u6cd5\u63d0\u53d6\u8de8\u7ea7\u9009\u4e2d\u7684\u8282\u70b9\u4ee3\u7801\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u901a\u8fc7\u9012\u5f52\u7b97\u6cd5\u63d0\u53d6\u8de8\u7ea7\u9009\u4e2d\u7684\u8282\u70b9\u4ee3\u7801\uff1f <\/h1>\n<p>\u5c0f\u4f19\u4f34\u4eec\u6709\u6ca1\u6709\u89c9\u5f97\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u5f88\u6709\u610f\u601d\uff1f\u6709\u610f\u601d\u5c31\u5bf9\u4e86\uff01\u4eca\u5929\u5c31\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5982\u4f55\u901a\u8fc7\u9012\u5f52\u7b97\u6cd5\u63d0\u53d6\u8de8\u7ea7\u9009\u4e2d\u7684\u8282\u70b9\u4ee3\u7801\uff1f \u300b<\/span>\uff0c\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u82e5\u662f\u5728\u5b66\u4e60\u4e2d\u5bf9\u5176\u4e2d\u90e8\u5206\u77e5\u8bc6\u70b9\u6709\u7591\u95ee\uff0c\u6216\u8bb8\u770b\u4e86\u672c\u6587\u5c31\u80fd\u5e2e\u5230\u4f60\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241127\/173267661567468c07339a1.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u901a\u8fc7\u9012\u5f52\u7b97\u6cd5\u63d0\u53d6\u8de8\u7ea7\u9009\u4e2d\u7684\u8282\u70b9\u4ee3\u7801\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u901a\u8fc7\u9012\u5f52\u7b97\u6cd5\u63d0\u53d6\u8de8\u7ea7\u9009\u4e2d\u7684\u8282\u70b9\u4ee3\u7801\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u8de8\u7ea7\u9009\u4e2d\u8282\u70b9\u4ee3\u7801\u63d0\u53d6<\/strong><\/p>\n<p>\u9488\u5bf9\u7701\u5e02\u533a\u7ed3\u6784\u6241\u5e73\u5316\u63d0\u53d6\u9009\u4e2d\u7684\u4ee3\u7801\uff0c\u6211\u4eec\u9700\u8981\u8fdb\u884c\u9012\u5f52\u5904\u7406\u3002<\/p>\n<p>\u5173\u952e\u6b65\u9aa4\u5728\u4e8e\u4f20\u9012\u9009\u4e2d\u7684\u72b6\u6001\u3002\u9012\u5f52\u65f6\uff0c\u5982\u679c\u4e0a\u5c42\u8282\u70b9\u9009\u4e2d\uff0c\u5219\u4e0b\u5c42\u6240\u6709\u5b50\u8282\u70b9\u90fd\u89c6\u4e3a\u9009\u4e2d\u72b6\u6001\u3002<\/p>\n<pre>\/**\n * \u83b7\u53d6\u6240\u6709\u88ab\u9009\u4e2d\u7684\u4ee3\u7801\n * @param {any[]} list \u6811\u5f62\u7ed3\u6784\n * @param {string[]} parentList \u5230\u7236\u7ea7\u6240\u6709\u7684\u4ee3\u7801\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  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>\u4f7f\u7528\u793a\u4f8b\uff1a<\/p>\n<pre>console.log(getCheckedList(tree));<\/pre>\n<p>\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300a\u5982\u4f55\u901a\u8fc7\u9012\u5f52\u7b97\u6cd5\u63d0\u53d6\u8de8\u7ea7\u9009\u4e2d\u7684\u8282\u70b9\u4ee3\u7801\uff1f \u300b\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5927\u5bb6\u90fd\u638c\u63e1\u4e86\u5427\uff01\u5982\u679c\u60f3\u8981\u7ee7\u7eed\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\uff0c\u90a3\u4e48\u5c31\u6765\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u5427\uff01<\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   \u8f7b\u677e\u8bbe\u7f6e\u7535\u8111\u52a8\u6001\u58c1\u7eb8\u7684\u5b8c\u6574\u6307\u5357\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u901a\u8fc7\u9012\u5f52\u7b97\u6cd5\u63d0\u53d6\u8de8\u7ea7\u9009\u4e2d\u7684\u8282\u70b9\u4ee3\u7801\uff1f \u5c0f\u4f19\u4f34\u4eec\u6709\u6ca1\u6709\u89c9\u5f97\u5b66\u4e60\u6587\u7ae0\u5f88\u6709\u610f\u601d\uff1f\u6709\u610f\u601d\u5c31\u5bf9\u4e86\uff01\u4eca\u5929\u5c31\u7ed9\u5927\u5bb6\u5e26\u6765\u300a\u5982\u4f55\u901a\u8fc7\u9012\u5f52\u7b97\u6cd5\u63d0\u53d6\u8de8\u7ea7\u9009\u4e2d\u7684\u8282\u70b9\u4ee3\u7801\uff1f \u300b\uff0c\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230\uff0c\u82e5\u662f\u5728\u5b66\u4e60\u4e2d\u5bf9\u5176\u4e2d\u90e8\u5206\u77e5\u8bc6\u70b9\u6709\u7591\u95ee\uff0c\u6216\u8bb8\u770b\u4e86\u672c\u6587\u5c31\u80fd\u5e2e\u5230\u4f60\uff01 \u8de8\u7ea7\u9009\u4e2d\u8282\u70b9\u4ee3\u7801\u63d0\u53d6 \u9488\u5bf9\u7701\u5e02\u533a\u7ed3\u6784\u6241\u5e73\u5316\u63d0\u53d6\u9009\u4e2d\u7684\u4ee3\u7801\uff0c\u6211\u4eec\u9700\u8981\u8fdb\u884c\u9012\u5f52\u5904\u7406\u3002 \u5173\u952e\u6b65\u9aa4\u5728\u4e8e\u4f20\u9012\u9009\u4e2d\u7684\u72b6\u6001\u3002\u9012\u5f52\u65f6\uff0c\u5982\u679c\u4e0a\u5c42\u8282\u70b9\u9009\u4e2d\uff0c\u5219\u4e0b\u5c42\u6240\u6709\u5b50\u8282\u70b9\u90fd\u89c6\u4e3a\u9009\u4e2d\u72b6\u6001\u3002 \/** * \u83b7\u53d6\u6240\u6709\u88ab\u9009\u4e2d\u7684\u4ee3\u7801 * @param {any[]} list \u6811\u5f62\u7ed3\u6784 * @param {string[]} parentList \u5230\u7236\u7ea7\u6240\u6709\u7684\u4ee3\u7801\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 = []; list.forEach((item) =&gt; { const checked = parentChecked || item.check; \/\/ \u7236\u7ea7\u88ab\u9009\u4e2d\u6216\u5f53\u524d\u88ab\u9009\u4e2d\uff0c\u5747\u8ba4\u4e3a\u662f\u88ab\u9009\u4e2d const codeList = [&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-53131","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53131","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=53131"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53131\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=53131"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=53131"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=53131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}