{"id":1238,"date":"2024-11-10T09:54:15","date_gmt":"2024-11-10T01:54:15","guid":{"rendered":"https:\/\/fwq.ai\/blog\/1238\/"},"modified":"2024-11-10T09:54:15","modified_gmt":"2024-11-10T01:54:15","slug":"%e5%a6%82%e4%bd%95%e4%bc%98%e5%8c%96%e4%bb%a3%e7%a0%81%e4%bb%a5%e6%8f%90%e5%8d%87%e6%80%a7%e8%83%bd%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/1238\/","title":{"rendered":"\u5982\u4f55\u4f18\u5316\u4ee3\u7801\u4ee5\u63d0\u5347\u6027\u80fd\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173033894470163.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f18\u5316\u4ee3\u7801\u4ee5\u63d0\u5347\u6027\u80fd\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f18\u5316\u4ee3\u7801\u4ee5\u63d0\u5347\u6027\u80fd\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f18\u5316\u4ee3\u7801<\/strong><\/p>\n<p>\u4e3a\u4e86\u4f18\u5316\u4ee3\u7801\uff0c\u53ef\u4ee5\u8003\u8651\u4ee5\u4e0b\u65b9\u6848\uff1a<\/p>\n<ul>\n<li><strong>\u4f7f\u7528\u6570\u7ec4\u6241\u5e73\u5316\u548c\u5faa\u73af<\/strong><\/li>\n<\/ul>\n<p>\u901a\u8fc7\u5c06 dataList \u6241\u5e73\u5316\uff0c\u53ef\u4ee5\u51cf\u5c11\u5d4c\u5957\u5faa\u73af\u7684\u6b21\u6570\u3002\u53ef\u4ee5\u4f7f\u7528 flatMap() \u65b9\u6cd5\u6765\u5b9e\u73b0\uff1a<\/p>\n<pre>dataList.flatMap(it =&gt; it.content)<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u7136\u540e\uff0c\u5bf9\u6241\u5e73\u5316\u7684\u6570\u7ec4\u8fdb\u884c\u5faa\u73af\uff1a<\/p>\n<pre>.forEach(it =&gt; {\n    \/\/ ...\n})<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ul>\n<li><strong>\u4f7f\u7528\u5bf9\u8c61\u89e3\u6784<\/strong><\/li>\n<\/ul>\n<p>\u5728\u5faa\u73af\u5185\u90e8\uff0c\u53ef\u4ee5\u4f7f\u7528\u5bf9\u8c61\u89e3\u6784\u6765\u63d0\u53d6\u6240\u9700\u7684\u952e\u548c\u503c\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>const { title, value, ...rest } = it;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ul>\n<li><strong>\u7b80\u5316\u6570\u636e\u8d4b\u503c<\/strong><\/li>\n<\/ul>\n<p>\u53ef\u4ee5\u7b80\u5316\u4f7f\u7528\u5bf9\u8c61\u952e\u8d4b\u503c\u7684\u8fc7\u7a0b\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>it.value = data[Object.keys(rest)[0]];<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u6574\u4f53\u4f18\u5316<\/strong><\/p>\n<ul>\n<li><strong>\u8003\u8651\u6570\u636e\u7ed3\u6784<\/strong><\/li>\n<\/ul>\n<p>\u8003\u8651\u540e\u7aef\u8fd4\u56de\u6570\u636e\u7684\u7ed3\u6784\uff0c\u5e76\u8bbe\u8ba1\u4e00\u4e2a\u66f4\u52a0\u7b26\u5408\u9700\u6c42\u7684\u6570\u636e\u7ed3\u6784\u3002\u8fd9\u53ef\u4ee5\u51cf\u5c11\u5ba2\u6237\u7aef\u4e0a\u7684\u5904\u7406\u65f6\u95f4\u3002<\/p>\n<ul>\n<li><strong>\u51cf\u5c11\u5d4c\u5957\u5faa\u73af<\/strong><\/li>\n<\/ul>\n<p>\u5d4c\u5957\u5faa\u73af\u4f1a\u964d\u4f4e\u4ee3\u7801\u6548\u7387\u3002\u5c3d\u53ef\u80fd\u51cf\u5c11\u5d4c\u5957\u5faa\u73af\u7684\u6b21\u6570\uff0c\u4f8b\u5982\u901a\u8fc7\u4f7f\u7528\u6570\u7ec4\u6241\u5e73\u5316\u6216\u5176\u4ed6\u6280\u672f\u3002<\/p>\n<ul>\n<li><strong>\u4f18\u5316\u8d4b\u503c\u64cd\u4f5c<\/strong><\/li>\n<\/ul>\n<p>\u4f7f\u7528\u5bf9\u8c61\u89e3\u6784\u6216\u5176\u4ed6\u6280\u672f\u4f18\u5316\u8d4b\u503c\u64cd\u4f5c\uff0c\u4ee5\u63d0\u9ad8\u6027\u80fd\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f18\u5316\u4ee3\u7801\u4ee5\u63d0\u5347\u6027\u80fd\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\u4f18\u5316\u4ee3\u7801 \u4e3a\u4e86\u4f18\u5316\u4ee3\u7801\uff0c\u53ef\u4ee5\u8003\u8651\u4ee5\u4e0b\u65b9\u6848\uff1a \u4f7f\u7528\u6570\u7ec4\u6241\u5e73\u5316\u548c\u5faa\u73af \u901a\u8fc7\u5c06 dataList \u6241\u5e73\u5316\uff0c\u53ef\u4ee5\u51cf\u5c11\u5d4c\u5957\u5faa\u73af\u7684\u6b21\u6570\u3002\u53ef\u4ee5\u4f7f\u7528 flatMap() \u65b9\u6cd5\u6765\u5b9e\u73b0\uff1a dataList.flatMap(it =&gt; it.content) \u767b\u5f55\u540e\u590d\u5236 \u7136\u540e\uff0c\u5bf9\u6241\u5e73\u5316\u7684\u6570\u7ec4\u8fdb\u884c\u5faa\u73af\uff1a .forEach(it =&gt; { \/\/ &#8230; }) \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528\u5bf9\u8c61\u89e3\u6784 \u5728\u5faa\u73af\u5185\u90e8\uff0c\u53ef\u4ee5\u4f7f\u7528\u5bf9\u8c61\u89e3\u6784\u6765\u63d0\u53d6\u6240\u9700\u7684\u952e\u548c\u503c\u3002\u4f8b\u5982\uff1a const { title, value, &#8230;rest } = it; \u767b\u5f55\u540e\u590d\u5236 \u7b80\u5316\u6570\u636e\u8d4b\u503c \u53ef\u4ee5\u7b80\u5316\u4f7f\u7528\u5bf9\u8c61\u952e\u8d4b\u503c\u7684\u8fc7\u7a0b\u3002\u4f8b\u5982\uff1a it.value = data[Object.keys(rest)[0]]; \u767b\u5f55\u540e\u590d\u5236 \u6574\u4f53\u4f18\u5316 \u8003\u8651\u6570\u636e\u7ed3\u6784 \u8003\u8651\u540e\u7aef\u8fd4\u56de\u6570\u636e\u7684\u7ed3\u6784\uff0c\u5e76\u8bbe\u8ba1\u4e00\u4e2a\u66f4\u52a0\u7b26\u5408\u9700\u6c42\u7684\u6570\u636e\u7ed3\u6784\u3002\u8fd9\u53ef\u4ee5\u51cf\u5c11\u5ba2\u6237\u7aef\u4e0a\u7684\u5904\u7406\u65f6\u95f4\u3002 \u51cf\u5c11\u5d4c\u5957\u5faa\u73af \u5d4c\u5957\u5faa\u73af\u4f1a\u964d\u4f4e\u4ee3\u7801\u6548\u7387\u3002\u5c3d\u53ef\u80fd\u51cf\u5c11\u5d4c\u5957\u5faa\u73af\u7684\u6b21\u6570\uff0c\u4f8b\u5982\u901a\u8fc7\u4f7f\u7528\u6570\u7ec4\u6241\u5e73\u5316\u6216\u5176\u4ed6\u6280\u672f\u3002 \u4f18\u5316\u8d4b\u503c\u64cd\u4f5c \u4f7f\u7528\u5bf9\u8c61\u89e3\u6784\u6216\u5176\u4ed6\u6280\u672f\u4f18\u5316\u8d4b\u503c\u64cd\u4f5c\uff0c\u4ee5\u63d0\u9ad8\u6027\u80fd\u3002 \u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f18\u5316\u4ee3\u7801\u4ee5\u63d0\u5347\u6027\u80fd\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},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-1238","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1238","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=1238"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1238\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=1238"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=1238"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=1238"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}