{"id":1263,"date":"2024-11-10T16:19:18","date_gmt":"2024-11-10T08:19:18","guid":{"rendered":"https:\/\/fwq.ai\/blog\/1263\/"},"modified":"2024-11-10T16:19:18","modified_gmt":"2024-11-10T08:19:18","slug":"%e5%a6%82%e4%bd%95%e4%bc%98%e5%8c%96%e5%89%8d%e7%ab%af%e4%bb%a3%e7%a0%81%e4%bb%a5%e7%ae%80%e5%8c%96%e6%95%b0%e6%8d%ae%e8%bd%ac%e6%8d%a2%e5%b9%b6%e6%8f%90%e5%8d%87%e6%80%a7%e8%83%bd%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/1263\/","title":{"rendered":"\u5982\u4f55\u4f18\u5316\u524d\u7aef\u4ee3\u7801\u4ee5\u7b80\u5316\u6570\u636e\u8f6c\u6362\u5e76\u63d0\u5347\u6027\u80fd\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173034523036216.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f18\u5316\u524d\u7aef\u4ee3\u7801\u4ee5\u7b80\u5316\u6570\u636e\u8f6c\u6362\u5e76\u63d0\u5347\u6027\u80fd\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f18\u5316\u524d\u7aef\u4ee3\u7801\u4ee5\u7b80\u5316\u6570\u636e\u8f6c\u6362\u5e76\u63d0\u5347\u6027\u80fd\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u4f18\u5316\u524d\u7aef\u4ee3\u7801\u4ee5\u6539\u5584\u6570\u636e\u8f6c\u6362<\/strong><\/p>\n<p>\u540e\u7aef\u8fd4\u56de\u7684\u6570\u636e\u9700\u8981\u4e0e\u524d\u7aef\u7684 HTML \u7ed3\u6784\u76f8\u5339\u914d\u3002\u7136\u800c\uff0c\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c&#8221;value&#8221;\u5b57\u6bb5\u88ab\u786c\u7f16\u7801\u5230 HTML \u4e2d\uff0c\u5bfc\u81f4\u4e86\u7e41\u7410\u7684 JavaScript \u8d4b\u503c\u903b\u8f91\u3002<\/p>\n<p><strong>\u4f18\u5316\u5efa\u8bae\uff1a<\/strong><\/p>\n<ul>\n<li>\u79fb\u9664 HTML \u4e2d\u4e0d\u5fc5\u8981\u7684 &#8220;value&#8221; \u5b57\u6bb5\u3002<\/li>\n<li>\u5728 JavaScript \u4e2d\u4f7f\u7528 Array.prototype.flatMap() \u548c Object.keys() \u6765\u7b80\u5316\u6570\u636e\u8f6c\u6362\u3002<\/li>\n<\/ul>\n<p><strong>\u4f18\u5316\u540e\u4ee3\u7801\uff1a<\/strong><\/p>\n<pre>const flattenedData = dataList.flatMap(it =&gt; it.content);\n\nflattenedData.forEach(it =&gt; {\n    const { title, ...rest } = it;\n    it.value = data[Object.keys(rest)[0]];\n});<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6574\u4f53\u4f18\u5316\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ul>\n<li>\u8003\u8651\u4f7f\u7528\u6570\u636e\u7ed1\u5b9a\u6846\u67b6\uff0c\u4f8b\u5982 Vue.js \u6216 React\uff0c\u4ee5\u7b80\u5316\u6570\u636e\u8f6c\u6362\u548c\u7ed1\u5b9a\u8fc7\u7a0b\u3002<\/li>\n<li>\u907f\u514d\u5728 JavaScript \u4e2d\u8fdb\u884c\u7e41\u7410\u7684\u624b\u52a8\u8d4b\u503c\uff0c\u800c\u662f\u4f7f\u7528\u6846\u67b6\u63d0\u4f9b\u7684\u54cd\u5e94\u5f0f\u7ed1\u5b9a\u673a\u5236\u3002<\/li>\n<li>\u4f18\u5316\u524d\u7aef API\uff0c\u4f8b\u5982\u4f7f\u7528\u5206\u9875\u548c\u7f13\u5b58\u6280\u672f\u6765\u63d0\u5347\u6027\u80fd\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f18\u5316\u524d\u7aef\u4ee3\u7801\u4ee5\u7b80\u5316\u6570\u636e\u8f6c\u6362\u5e76\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>\u4f18\u5316\u524d\u7aef\u4ee3\u7801\u4ee5\u6539\u5584\u6570\u636e\u8f6c\u6362 \u540e\u7aef\u8fd4\u56de\u7684\u6570\u636e\u9700\u8981\u4e0e\u524d\u7aef\u7684 HTML \u7ed3\u6784\u76f8\u5339\u914d\u3002\u7136\u800c\uff0c\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c&#8221;value&#8221;\u5b57\u6bb5\u88ab\u786c\u7f16\u7801\u5230 HTML \u4e2d\uff0c\u5bfc\u81f4\u4e86\u7e41\u7410\u7684 JavaScript \u8d4b\u503c\u903b\u8f91\u3002 \u4f18\u5316\u5efa\u8bae\uff1a \u79fb\u9664 HTML \u4e2d\u4e0d\u5fc5\u8981\u7684 &#8220;value&#8221; \u5b57\u6bb5\u3002 \u5728 JavaScript \u4e2d\u4f7f\u7528 Array.prototype.flatMap() \u548c Object.keys() \u6765\u7b80\u5316\u6570\u636e\u8f6c\u6362\u3002 \u4f18\u5316\u540e\u4ee3\u7801\uff1a const flattenedData = dataList.flatMap(it =&gt; it.content); flattenedData.forEach(it =&gt; { const { title, &#8230;rest } = it; it.value = data[Object.keys(rest)[0]]; }); \u767b\u5f55\u540e\u590d\u5236 \u6574\u4f53\u4f18\u5316\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u8003\u8651\u4f7f\u7528\u6570\u636e\u7ed1\u5b9a\u6846\u67b6\uff0c\u4f8b\u5982 Vue.js \u6216 React\uff0c\u4ee5\u7b80\u5316\u6570\u636e\u8f6c\u6362\u548c\u7ed1\u5b9a\u8fc7\u7a0b\u3002 \u907f\u514d\u5728 JavaScript \u4e2d\u8fdb\u884c\u7e41\u7410\u7684\u624b\u52a8\u8d4b\u503c\uff0c\u800c\u662f\u4f7f\u7528\u6846\u67b6\u63d0\u4f9b\u7684\u54cd\u5e94\u5f0f\u7ed1\u5b9a\u673a\u5236\u3002 \u4f18\u5316\u524d\u7aef API\uff0c\u4f8b\u5982\u4f7f\u7528\u5206\u9875\u548c\u7f13\u5b58\u6280\u672f\u6765\u63d0\u5347\u6027\u80fd\u3002 \u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f18\u5316\u524d\u7aef\u4ee3\u7801\u4ee5\u7b80\u5316\u6570\u636e\u8f6c\u6362\u5e76\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-1263","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1263","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=1263"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1263\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=1263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=1263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=1263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}