{"id":26546,"date":"2024-11-24T08:46:17","date_gmt":"2024-11-24T00:46:17","guid":{"rendered":"https:\/\/fwq.ai\/blog\/26546\/"},"modified":"2024-11-24T08:46:17","modified_gmt":"2024-11-24T00:46:17","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8%e5%af%b9%e8%b1%a1%e5%92%8c%e6%95%b0%e7%bb%84%e4%bc%98%e9%9b%85%e5%9c%b0%e5%b0%86%e5%a7%93%e5%90%8d%e5%92%8c%e5%b9%b4%e9%be%84%e6%95%b0%e6%8d%ae%e5%88%86%e7%bb%84-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/26546\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528\u5bf9\u8c61\u548c\u6570\u7ec4\u4f18\u96c5\u5730\u5c06\u59d3\u540d\u548c\u5e74\u9f84\u6570\u636e\u5206\u7ec4\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173098192448830.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528\u5bf9\u8c61\u548c\u6570\u7ec4\u4f18\u96c5\u5730\u5c06\u59d3\u540d\u548c\u5e74\u9f84\u6570\u636e\u5206\u7ec4\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528\u5bf9\u8c61\u548c\u6570\u7ec4\u4f18\u96c5\u5730\u5c06\u59d3\u540d\u548c\u5e74\u9f84\u6570\u636e\u5206\u7ec4\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5de7\u7528\u5bf9\u8c61\u548c\u6570\u7ec4\u5b9e\u73b0\u4f18\u96c5\u6570\u636e\u8f6c\u6362<\/strong><\/p>\n<p>\u73b0\u6709\u539f\u59cb\u6570\u636e\u6570\u7ec4\uff0c\u5305\u542b\u59d3\u540d\u548c\u5e74\u9f84\u4fe1\u606f\u3002\u4e3a\u4e86\u4fbf\u4e8e\u5c55\u793a\uff0c\u6211\u4eec\u9700\u8981\u5c06\u6570\u636e\u8f6c\u6362\u4e3a\u76ee\u6807\u6570\u636e\u683c\u5f0f\uff0c\u5373\u6839\u636e\u5e74\u9f84\u5bf9\u59d3\u540d\u8fdb\u884c\u5206\u7ec4\u3002\u4f20\u7edf\u7684\u6570\u636e\u5faa\u73af\u8f6c\u6362\u65b9\u5f0f\u53ef\u80fd\u8f83\u4e3a\u7e41\u7410\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u4e00\u79cd\u66f4\u4f18\u96c5\u7684\u8f6c\u6362\u65b9\u6cd5\u3002<\/p>\n<h3>\u89e3\u51b3\u65b9\u6848<\/h3>\n<p>\u9996\u5148\uff0c\u4f7f\u7528\u4e00\u4e2a\u4e34\u65f6\u5bf9\u8c61\u5bf9\u6570\u636e\u8fdb\u884c\u9884\u5904\u7406\u3002\u904d\u5386\u539f\u59cb\u6570\u7ec4\uff0c\u5c06\u59d3\u540d\u4f5c\u4e3a\u503c\uff0c\u5e74\u9f84\u4f5c\u4e3a\u952e\u6dfb\u52a0\u81f3\u5bf9\u8c61\u4e2d\uff1a<\/p>\n<pre>let temp = {};\narr.forEach(item =&gt; {\n    if (!temp[item.age]) {\n        temp[item.age] = [];\n    }\n    temp[item.age].push(item.name);\n});<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u5c06\u4e34\u65f6\u5bf9\u8c61\u8f6c\u6362\u4e3a\u76ee\u6807\u6570\u7ec4\u3002\u9996\u5148\u83b7\u53d6\u5bf9\u8c61\u7684\u6240\u6709\u503c\uff0c\u5373\u5206\u522b\u5305\u542b\u4e0d\u540c\u5e74\u9f84\u7ec4\u59d3\u540d\u7684\u6570\u7ec4\u3002\u7136\u540e\u5bf9\u6bcf\u4e2a\u6570\u7ec4\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a<\/p>\n<pre>value.forEach((name, index) =&gt; {\n    if (!targetArr[index]) {\n        targetArr[index] = {};\n    }\n    Object.keys(temp).forEach(key =&gt; {\n        if (key in targetArr[index]) {\n            return;\n        }\n        targetArr[index][key] = '';\n    });\n    targetArr[index][Object.keys(temp).find(key =&gt; temp[key] === value)] = name;\n});<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8fd9\u90e8\u5206\u4ee3\u7801\u7684\u4f5c\u7528\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>\u521d\u59cb\u5316\u76ee\u6807\u6570\u7ec4\u4e2d\u7684\u4e00\u4e2a\u65b0\u5bf9\u8c61\u3002<\/li>\n<li>\u904d\u5386\u4e34\u65f6\u5bf9\u8c61\u4e2d\u7684\u6240\u6709\u952e\uff0c\u6dfb\u52a0\u7a7a\u5b57\u7b26\u4e32\u4f5c\u4e3a\u7f3a\u7701\u503c\u3002<\/li>\n<li>\u627e\u5230\u5339\u914d\u5f53\u524d\u6570\u7ec4\u7684\u5e74\u9f84\u952e\uff0c\u5e76\u5c06\u59d3\u540d\u6dfb\u52a0\u5230\u76f8\u5e94\u4f4d\u7f6e\u3002<\/li>\n<\/ul>\n<p>\u6700\u7ec8\uff0c\u76ee\u6807\u6570\u7ec4\u5373\u5df2\u751f\u6210\u7684\u6240\u9700\u6570\u636e\u683c\u5f0f\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u4f18\u96c5\u9ad8\u6548\u5730\u89e3\u51b3\u6570\u636e\u8f6c\u6362\u95ee\u9898\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528\u5bf9\u8c61\u548c\u6570\u7ec4\u4f18\u96c5\u5730\u5c06\u59d3\u540d\u548c\u5e74\u9f84\u6570\u636e\u5206\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>\u5de7\u7528\u5bf9\u8c61\u548c\u6570\u7ec4\u5b9e\u73b0\u4f18\u96c5\u6570\u636e\u8f6c\u6362 \u73b0\u6709\u539f\u59cb\u6570\u636e\u6570\u7ec4\uff0c\u5305\u542b\u59d3\u540d\u548c\u5e74\u9f84\u4fe1\u606f\u3002\u4e3a\u4e86\u4fbf\u4e8e\u5c55\u793a\uff0c\u6211\u4eec\u9700\u8981\u5c06\u6570\u636e\u8f6c\u6362\u4e3a\u76ee\u6807\u6570\u636e\u683c\u5f0f\uff0c\u5373\u6839\u636e\u5e74\u9f84\u5bf9\u59d3\u540d\u8fdb\u884c\u5206\u7ec4\u3002\u4f20\u7edf\u7684\u6570\u636e\u5faa\u73af\u8f6c\u6362\u65b9\u5f0f\u53ef\u80fd\u8f83\u4e3a\u7e41\u7410\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u4e00\u79cd\u66f4\u4f18\u96c5\u7684\u8f6c\u6362\u65b9\u6cd5\u3002 \u89e3\u51b3\u65b9\u6848 \u9996\u5148\uff0c\u4f7f\u7528\u4e00\u4e2a\u4e34\u65f6\u5bf9\u8c61\u5bf9\u6570\u636e\u8fdb\u884c\u9884\u5904\u7406\u3002\u904d\u5386\u539f\u59cb\u6570\u7ec4\uff0c\u5c06\u59d3\u540d\u4f5c\u4e3a\u503c\uff0c\u5e74\u9f84\u4f5c\u4e3a\u952e\u6dfb\u52a0\u81f3\u5bf9\u8c61\u4e2d\uff1a let temp = {}; arr.forEach(item =&gt; { if (!temp[item.age]) { temp[item.age] = []; } temp[item.age].push(item.name); }); \u767b\u5f55\u540e\u590d\u5236 \u63a5\u4e0b\u6765\uff0c\u5c06\u4e34\u65f6\u5bf9\u8c61\u8f6c\u6362\u4e3a\u76ee\u6807\u6570\u7ec4\u3002\u9996\u5148\u83b7\u53d6\u5bf9\u8c61\u7684\u6240\u6709\u503c\uff0c\u5373\u5206\u522b\u5305\u542b\u4e0d\u540c\u5e74\u9f84\u7ec4\u59d3\u540d\u7684\u6570\u7ec4\u3002\u7136\u540e\u5bf9\u6bcf\u4e2a\u6570\u7ec4\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a value.forEach((name, index) =&gt; { if (!targetArr[index]) { targetArr[index] = {}; } Object.keys(temp).forEach(key =&gt; { if (key in targetArr[index]) { return; } targetArr[index][key] = &#8221;; }); targetArr[index][Object.keys(temp).find(key =&gt; temp[key] === value)] = name; }); [&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-26546","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26546","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=26546"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26546\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=26546"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=26546"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=26546"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}