{"id":1210,"date":"2024-11-10T16:03:34","date_gmt":"2024-11-10T08:03:34","guid":{"rendered":"https:\/\/fwq.ai\/blog\/1210\/"},"modified":"2024-11-10T16:03:34","modified_gmt":"2024-11-10T08:03:34","slug":"%e5%a6%82%e4%bd%95%e4%bc%98%e5%8c%96%e5%90%8e%e7%ab%af-json-%e6%95%b0%e6%8d%ae%e4%b8%8e%e5%89%8d%e7%ab%af-html-%e5%ad%97%e6%ae%b5%e5%90%8d%e4%b8%8d%e4%b8%80%e8%87%b4%e7%9a%84%e5%b5%8c%e5%a5%97","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/1210\/","title":{"rendered":"\u5982\u4f55\u4f18\u5316\u540e\u7aef JSON \u6570\u636e\u4e0e\u524d\u7aef HTML \u5b57\u6bb5\u540d\u4e0d\u4e00\u81f4\u7684\u5d4c\u5957\u8d4b\u503c\u4ee3\u7801\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173029824799664.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f18\u5316\u540e\u7aef JSON \u6570\u636e\u4e0e\u524d\u7aef HTML \u5b57\u6bb5\u540d\u4e0d\u4e00\u81f4\u7684\u5d4c\u5957\u8d4b\u503c\u4ee3\u7801\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f18\u5316\u540e\u7aef JSON \u6570\u636e\u4e0e\u524d\u7aef HTML \u5b57\u6bb5\u540d\u4e0d\u4e00\u81f4\u7684\u5d4c\u5957\u8d4b\u503c\u4ee3\u7801\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f18\u5316\u5d4c\u5957\u8d4b\u503c\u4ee3\u7801\uff1f<\/strong><\/p>\n<p>\u540e\u7aef\u8fd4\u56de\u7684 JSON \u6570\u636e\u5b57\u6bb5\u4e0e\u524d\u7aef HTML \u9884\u671f\u7684\u5b57\u6bb5\u540d\u4e0d\u4e00\u81f4\uff0c\u5bfc\u81f4\u9700\u8981\u5728 JS \u4e2d\u624b\u52a8\u8d4b\u503c\u3002\u8be5\u4ee3\u7801\u8fdb\u884c\u4e86\u5927\u91cf\u7684\u5d4c\u5957\u5faa\u73af\u548c\u5197\u4f59\u7684\u952e\u503c\u6bd4\u5bf9\uff0c\u6548\u7387\u4f4e\u4e0b\u3002<\/p>\n<p><strong>\u4f18\u5316\u5efa\u8bae\uff1a<\/strong><\/p>\n<p>\u4f7f\u7528 flatMap \u548c ES6 \u89e3\u6784\u6765\uff1a<\/p>\n<pre>dataList.flatMap(it =&gt; it.content)\n    .forEach(it =&gt; {\n        const { title, value, ...rest } = it;\n        it.value = data[Object.keys(rest)[0]];\n    });<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f18\u5316\u540e\u7684\u4ee3\u7801\u4f18\u52bf\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ul>\n<li>\u4f7f\u7528 flatMap \u5c06\u5d4c\u5957\u6570\u7ec4\u5c55\u5e73\uff0c\u7b80\u5316\u5faa\u73af\u7ed3\u6784\u3002<\/li>\n<li>\u4f7f\u7528 ES6 \u89e3\u6784\u76f4\u63a5\u83b7\u53d6\u9700\u8981\u5904\u7406\u7684\u5b57\u6bb5\uff0c\u7701\u53bb\u5197\u4f59\u7684 key \u5bf9\u6bd4\u3002<\/li>\n<li>\u7b80\u5316\u4e86\u4ee3\u7801\uff0c\u63d0\u9ad8\u4e86\u6548\u7387\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f18\u5316\u540e\u7aef JSON \u6570\u636e\u4e0e\u524d\u7aef HTML \u5b57\u6bb5\u540d\u4e0d\u4e00\u81f4\u7684\u5d4c\u5957\u8d4b\u503c\u4ee3\u7801\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\u5d4c\u5957\u8d4b\u503c\u4ee3\u7801\uff1f \u540e\u7aef\u8fd4\u56de\u7684 JSON \u6570\u636e\u5b57\u6bb5\u4e0e\u524d\u7aef HTML \u9884\u671f\u7684\u5b57\u6bb5\u540d\u4e0d\u4e00\u81f4\uff0c\u5bfc\u81f4\u9700\u8981\u5728 JS \u4e2d\u624b\u52a8\u8d4b\u503c\u3002\u8be5\u4ee3\u7801\u8fdb\u884c\u4e86\u5927\u91cf\u7684\u5d4c\u5957\u5faa\u73af\u548c\u5197\u4f59\u7684\u952e\u503c\u6bd4\u5bf9\uff0c\u6548\u7387\u4f4e\u4e0b\u3002 \u4f18\u5316\u5efa\u8bae\uff1a \u4f7f\u7528 flatMap \u548c ES6 \u89e3\u6784\u6765\uff1a dataList.flatMap(it =&gt; it.content) .forEach(it =&gt; { const { title, value, &#8230;rest } = it; it.value = data[Object.keys(rest)[0]]; }); \u767b\u5f55\u540e\u590d\u5236 \u4f18\u5316\u540e\u7684\u4ee3\u7801\u4f18\u52bf\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u4f7f\u7528 flatMap \u5c06\u5d4c\u5957\u6570\u7ec4\u5c55\u5e73\uff0c\u7b80\u5316\u5faa\u73af\u7ed3\u6784\u3002 \u4f7f\u7528 ES6 \u89e3\u6784\u76f4\u63a5\u83b7\u53d6\u9700\u8981\u5904\u7406\u7684\u5b57\u6bb5\uff0c\u7701\u53bb\u5197\u4f59\u7684 key \u5bf9\u6bd4\u3002 \u7b80\u5316\u4e86\u4ee3\u7801\uff0c\u63d0\u9ad8\u4e86\u6548\u7387\u3002 \u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f18\u5316\u540e\u7aef JSON \u6570\u636e\u4e0e\u524d\u7aef HTML \u5b57\u6bb5\u540d\u4e0d\u4e00\u81f4\u7684\u5d4c\u5957\u8d4b\u503c\u4ee3\u7801\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-1210","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1210","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=1210"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1210\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=1210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=1210"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=1210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}