{"id":52976,"date":"2024-12-03T09:54:36","date_gmt":"2024-12-03T01:54:36","guid":{"rendered":"https:\/\/fwq.ai\/blog\/52976\/"},"modified":"2024-12-03T09:54:36","modified_gmt":"2024-12-03T01:54:36","slug":"%e5%a6%82%e4%bd%95%e5%b0%86%e6%89%81%e5%b9%b3%e5%8c%96%e7%9c%81%e5%b8%82%e5%8c%ba%e6%a0%91%e7%bb%93%e6%9e%84%e4%b8%ad%e7%9a%84%e9%80%89%e4%b8%ad%e9%a1%b9%e8%bf%9b%e8%a1%8c%e6%89%81%e5%b9%b3%e5%8c%96-3","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/52976\/","title":{"rendered":"\u5982\u4f55\u5c06\u6241\u5e73\u5316\u7701\u5e02\u533a\u6811\u7ed3\u6784\u4e2d\u7684\u9009\u4e2d\u9879\u8fdb\u884c\u6241\u5e73\u5316\u8f6c\u6362\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u5c06\u6241\u5e73\u5316\u7701\u5e02\u533a\u6811\u7ed3\u6784\u4e2d\u7684\u9009\u4e2d\u9879\u8fdb\u884c\u6241\u5e73\u5316\u8f6c\u6362\uff1f <\/h1>\n<p>\u6700\u8fd1\u53d1\u73b0\u4e0d\u5c11\u5c0f\u4f19\u4f34\u90fd\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u5f88\u611f\u5174\u8da3\uff0c\u6240\u4ee5\u4eca\u5929\u7ee7\u7eed\u7ed9\u5927\u5bb6\u4ecb\u7ecd<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u76f8\u5173\u7684\u77e5\u8bc6\uff0c\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5982\u4f55\u5c06\u6241\u5e73\u5316\u7701\u5e02\u533a\u6811\u7ed3\u6784\u4e2d\u7684\u9009\u4e2d\u9879\u8fdb\u884c\u6241\u5e73\u5316\u8f6c\u6362\uff1f \u300b<\/span>\u4e3b\u8981\u5185\u5bb9\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01\u5f53\u7136\u5982\u679c\u9605\u8bfb\u672c\u6587\u65f6\u5b58\u5728\u4e0d\u540c\u60f3\u6cd5\uff0c\u53ef\u4ee5\u5728\u8bc4\u8bba\u4e2d\u8868\u8fbe\uff0c\u4f46\u662f\u8bf7\u52ff\u4f7f\u7528\u8fc7\u6fc0\u7684\u63aa\u8f9e~<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241125\/17325070646743f5b8e6e3d.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5c06\u6241\u5e73\u5316\u7701\u5e02\u533a\u6811\u7ed3\u6784\u4e2d\u7684\u9009\u4e2d\u9879\u8fdb\u884c\u6241\u5e73\u5316\u8f6c\u6362\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5c06\u6241\u5e73\u5316\u7701\u5e02\u533a\u6811\u7ed3\u6784\u4e2d\u7684\u9009\u4e2d\u9879\u8fdb\u884c\u6241\u5e73\u5316\u8f6c\u6362\uff1f\u63d2\u56fe\" \/><\/p>\n<p>\u6241\u5e73\u5316\u7701\u5e02\u533a\u6811\u7ed3\u6784\u4e2d\u7684\u9009\u4e2d\u9879<\/p>\n<p>\u5728\u7701\u5e02\u533a\u6811\u5f62\u7ed3\u6784\u4e2d\uff0c\u9700\u8981\u5bf9\u9009\u4e2d\u9879\u8fdb\u884c\u6241\u5e73\u5316\u8f6c\u6362\u3002\u6811\u5f62\u7ed3\u6784\u7c7b\u4f3c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>{\n  \"code\": \"110000\",\n  \"value\": \"\u5317\u4eac\u5e02\",\n  \"check\": 1, \/\/ \u9009\u4e2d\u6807\u8bc6\n  \"children\": [\n    {\n      \"code\": \"110100\",\n      \"value\": \"\u5317\u4eac\u5e02\",\n      \"check\": null, \/\/ \u672a\u9009\u4e2d\u6807\u8bc6\n      \"children\": [\n        {\n          \"code\": \"110101\",\n          \"value\": \"\u4e1c\u57ce\u533a\",\n          \"check\": null \/\/ \u672a\u9009\u4e2d\u6807\u8bc6\n        },\n        {\n          \"code\": \"110102\",\n          \"value\": \"\u897f\u57ce\u533a\",\n          \"check\": null \/\/ \u672a\u9009\u4e2d\u6807\u8bc6\n        }\n      ]\n    }\n  ]\n}<\/pre>\n<p>\u6241\u5e73\u5316\u540e\u7684\u7ed3\u679c\u9700\u8981\u6ee1\u8db3\u5982\u4e0b\u8981\u6c42\uff1a<\/p>\n<ol>\n<li>\u5982\u679c\u4e00\u7ea7\u9009\u4e2d\uff0c\u5219\u8bb0\u5f55\u4e00\u7ea7\u3001\u4e8c\u7ea7\u548c\u4e09\u7ea7code<\/li>\n<li>\u5982\u679c\u4e8c\u7ea7\u9009\u4e2d\uff0c\u5219\u8bb0\u5f55\u4e8c\u7ea7\u548c\u4e09\u7ea7code<\/li>\n<li>\u5982\u679c\u4e09\u7ea7\u9009\u4e2d\uff0c\u5219\u4ec5\u8bb0\u5f55\u4e09\u7ea7code<\/li>\n<\/ol>\n<p>\u6700\u7ec8\u6241\u5e73\u5316\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n<pre>[\n  [110000, 110100, 110101],\n  [110000, 110100, 110102]\n]<\/pre>\n<p>\u5b9e\u73b0\u6241\u5e73\u5316\u7684\u601d\u8def\u662f\u8fdb\u884c\u9012\u5f52\u904d\u5386\uff0c\u5c06\u9009\u4e2d\u6807\u8bc6\u4f20\u9012\u4e0b\u53bb\u3002\u4ee3\u7801\u5982\u4e0b\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>\u4f7f\u7528\u793a\u4f8b\uff1a<\/p>\n<pre>const tree = [\n  {\n    \"code\": \"110000\",\n    \"value\": \"\u5317\u4eac\u5e02\",\n    \"check\": 1,\n    \"children\": [\n      {\n        \"code\": \"110100\",\n        \"value\": \"\u5317\u4eac\u5e02\",\n        \"check\": null,\n        \"children\": [\n          {\n            \"code\": \"110101\",\n            \"value\": \"\u4e1c\u57ce\u533a\",\n            \"check\": null\n          },\n          {\n            \"code\": \"110102\",\n            \"value\": \"\u897f\u57ce\u533a\",\n            \"check\": null\n          }\n        ]\n      }\n    ]\n  },\n  {\n    \"code\": \"130000\",\n    \"value\": \"\u6cb3\u5317\u7701\",\n    \"check\": null,\n    \"children\": [\n      {\n        \"code\": \"130100\",\n        \"value\": \"\u77f3\u5bb6\u5e84\u5e02\",\n        \"check\": \"1\",\n        \"children\": [\n          {\n            \"code\": \"130102\",\n            \"value\": \"\u957f\u5b89\u533a\",\n            \"check\": null\n          },\n          {\n            \"code\": \"130104\",\n            \"value\": \"\u6865\u897f\u533a\",\n            \"check\": null\n          }\n        ]\n      },\n      {\n        \"code\": \"130200\",\n        \"value\": \"\u5510\u5c71\u5e02\",\n        \"check\": null,\n        \"children\": [\n          {\n            \"code\": \"130202\",\n            \"value\": \"\u8def\u5357\u533a\",\n            \"check\": null,\n          },\n          {\n            \"code\": \"130203\",\n            \"value\": \"\u8def\u5317\u533a\",\n            \"check\": null,\n          }\n        ]\n      }\n    ]\n  },\n  {\n    \"code\": \"150000\",\n    \"value\": \"\u5185\u8499\u53e4\u81ea\u6cbb\u533a\",\n    \"check\": null,\n    \"children\": [\n      {\n        \"code\": \"150100\",\n        \"value\": \"\u547c\u548c\u6d69\u7279\u5e02\",\n        \"check\": null,\n        \"children\": [\n          {\n            \"code\": \"150102\",\n            \"value\": \"\u65b0\u57ce\u533a\",\n            \"check\": null\n          },\n          {\n            \"code\": \"150103\",\n            \"value\": \"\u56de\u6c11\u533a\",\n            \"check\": 1\n          }\n        ]\n      }\n    ]\n  }\n];\n\nconsole.log(getCheckedList(tree));  \/\/ [ [ '110000', '110100', '110101' ], [ '110000', '110100', '110102' ], [ '130000', '130100', '130102' ], [ '130000', '130100', '130104' ], [ '150000', '150100', '150103' ] ]<\/pre>\n<p>\u4eca\u5929\u5173\u4e8e\u300a\u5982\u4f55\u5c06\u6241\u5e73\u5316\u7701\u5e02\u533a\u6811\u7ed3\u6784\u4e2d\u7684\u9009\u4e2d\u9879\u8fdb\u884c\u6241\u5e73\u5316\u8f6c\u6362\uff1f \u300b\u7684\u5185\u5bb9\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\uff0c\u5982\u679c\u6709\u4ec0\u4e48\u7591\u95ee\u6216\u8005\u5efa\u8bae\uff0c\u53ef\u4ee5\u5728\u7c73\u4e91\u516c\u4f17\u53f7\u4e0b\u591a\u591a\u56de\u590d\u4ea4\u6d41\uff1b\u6587\u4e2d\u82e5\u6709\u4e0d\u6b63\u4e4b\u5904\uff0c\u4e5f\u5e0c\u671b\u56de\u590d\u7559\u8a00\u4ee5\u544a\u77e5\uff01<\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   MySQL \u4e2d\u7684\u5012\u6392\u7d22\u5f15\u4e3a\u4f55\u9c9c\u4e3a\u4eba\u77e5\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5c06\u6241\u5e73\u5316\u7701\u5e02\u533a\u6811\u7ed3\u6784\u4e2d\u7684\u9009\u4e2d\u9879\u8fdb\u884c\u6241\u5e73\u5316\u8f6c\u6362\uff1f \u6700\u8fd1\u53d1\u73b0\u4e0d\u5c11\u5c0f\u4f19\u4f34\u90fd\u5bf9\u6587\u7ae0\u5f88\u611f\u5174\u8da3\uff0c\u6240\u4ee5\u4eca\u5929\u7ee7\u7eed\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u6587\u7ae0\u76f8\u5173\u7684\u77e5\u8bc6\uff0c\u672c\u6587\u300a\u5982\u4f55\u5c06\u6241\u5e73\u5316\u7701\u5e02\u533a\u6811\u7ed3\u6784\u4e2d\u7684\u9009\u4e2d\u9879\u8fdb\u884c\u6241\u5e73\u5316\u8f6c\u6362\uff1f \u300b\u4e3b\u8981\u5185\u5bb9\u6d89\u53ca\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01\u5f53\u7136\u5982\u679c\u9605\u8bfb\u672c\u6587\u65f6\u5b58\u5728\u4e0d\u540c\u60f3\u6cd5\uff0c\u53ef\u4ee5\u5728\u8bc4\u8bba\u4e2d\u8868\u8fbe\uff0c\u4f46\u662f\u8bf7\u52ff\u4f7f\u7528\u8fc7\u6fc0\u7684\u63aa\u8f9e~ \u6241\u5e73\u5316\u7701\u5e02\u533a\u6811\u7ed3\u6784\u4e2d\u7684\u9009\u4e2d\u9879 \u5728\u7701\u5e02\u533a\u6811\u5f62\u7ed3\u6784\u4e2d\uff0c\u9700\u8981\u5bf9\u9009\u4e2d\u9879\u8fdb\u884c\u6241\u5e73\u5316\u8f6c\u6362\u3002\u6811\u5f62\u7ed3\u6784\u7c7b\u4f3c\u5982\u4e0b\u6240\u793a\uff1a { &#8220;code&#8221;: &#8220;110000&#8221;, &#8220;value&#8221;: &#8220;\u5317\u4eac\u5e02&#8221;, &#8220;check&#8221;: 1, \/\/ \u9009\u4e2d\u6807\u8bc6 &#8220;children&#8221;: [ { &#8220;code&#8221;: &#8220;110100&#8221;, &#8220;value&#8221;: &#8220;\u5317\u4eac\u5e02&#8221;, &#8220;check&#8221;: null, \/\/ \u672a\u9009\u4e2d\u6807\u8bc6 &#8220;children&#8221;: [ { &#8220;code&#8221;: &#8220;110101&#8221;, &#8220;value&#8221;: &#8220;\u4e1c\u57ce\u533a&#8221;, &#8220;check&#8221;: null \/\/ \u672a\u9009\u4e2d\u6807\u8bc6 }, { &#8220;code&#8221;: &#8220;110102&#8221;, &#8220;value&#8221;: &#8220;\u897f\u57ce\u533a&#8221;, &#8220;check&#8221;: null \/\/ \u672a\u9009\u4e2d\u6807\u8bc6 } ] } ] } \u6241\u5e73\u5316\u540e\u7684\u7ed3\u679c\u9700\u8981\u6ee1\u8db3\u5982\u4e0b\u8981\u6c42\uff1a \u5982\u679c\u4e00\u7ea7\u9009\u4e2d\uff0c\u5219\u8bb0\u5f55\u4e00\u7ea7\u3001\u4e8c\u7ea7\u548c\u4e09\u7ea7code \u5982\u679c\u4e8c\u7ea7\u9009\u4e2d\uff0c\u5219\u8bb0\u5f55\u4e8c\u7ea7\u548c\u4e09\u7ea7code \u5982\u679c\u4e09\u7ea7\u9009\u4e2d\uff0c\u5219\u4ec5\u8bb0\u5f55\u4e09\u7ea7code [&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-52976","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52976","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=52976"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52976\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=52976"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=52976"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=52976"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}