{"id":1295,"date":"2024-11-10T14:29:14","date_gmt":"2024-11-10T06:29:14","guid":{"rendered":"https:\/\/fwq.ai\/blog\/1295\/"},"modified":"2024-11-10T14:29:14","modified_gmt":"2024-11-10T06:29:14","slug":"%e5%a6%82%e4%bd%95%e4%bc%98%e5%8c%96js%e4%bb%a3%e7%a0%81%e5%92%8chtml%e4%bb%a3%e7%a0%81%ef%bc%8c%e6%8f%90%e5%8d%87%e6%95%b0%e6%8d%ae%e5%b1%95%e7%a4%ba%e6%95%88%e7%8e%87%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/1295\/","title":{"rendered":"\u5982\u4f55\u4f18\u5316JS\u4ee3\u7801\u548cHTML\u4ee3\u7801\uff0c\u63d0\u5347\u6570\u636e\u5c55\u793a\u6548\u7387\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173035721394059.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f18\u5316JS\u4ee3\u7801\u548cHTML\u4ee3\u7801\uff0c\u63d0\u5347\u6570\u636e\u5c55\u793a\u6548\u7387\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f18\u5316JS\u4ee3\u7801\u548cHTML\u4ee3\u7801\uff0c\u63d0\u5347\u6570\u636e\u5c55\u793a\u6548\u7387\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f18\u5316\u5c55\u793a\u6570\u636e\u4ee3\u7801<\/strong><\/p>\n<h2>JS \u4f18\u5316<\/h2>\n<p>\u539f\u4ee3\u7801\u901a\u8fc7\u5d4c\u5957\u5faa\u73af\u67e5\u627e\u6570\u636e\u6e90\u4e2d\u7684\u5bf9\u5e94\u9879\uff0c\u6548\u7387\u8f83\u4f4e\u3002\u4f18\u5316\u65b9\u5f0f\u5982\u4e0b\uff1a<\/p>\n<pre>const data = { \/* ... *\/ };\ndataList.flatMap(it =&gt; it.content)\n    .forEach(it =&gt; {\n        \/\/ \u63d0\u53d6 key\n        const key = Object.keys(it)[0];\n        it.value = data[key];\n    });<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5c06\u6241\u5e73\u5316\u5904\u7406\u540e\u7684 dataList \u4e2d\u7684\u5143\u7d20\u9010\u4e00\u904d\u5386\uff0c\u76f4\u63a5\u83b7\u53d6\u5bf9\u5e94\u7684 value\uff0c\u7701\u53bb\u591a\u5c42\u5d4c\u5957\u5faa\u73af\u3002<\/p>\n<h2>HTML \u4f18\u5316<\/h2>\n<p>\u4e3a\u6ee1\u8db3\u6e32\u67d3\u9700\u6c42\uff0c\u539f\u4ee3\u7801\u5728\u6570\u636e\u6e90\u4e2d\u6dfb\u52a0\u4e86\u65e0\u610f\u4e49\u7684 value \u5b57\u6bb5\u3002\u4f18\u5316\u65b9\u5f0f\u662f\u907f\u514d\u5c06\u65e0\u5173\u5b57\u6bb5\u6dfb\u52a0\u5230\u6570\u636e\u6e90\u4e2d\uff0c\u5728 HTML \u4e2d\u6839\u636e\u9700\u8981\u81ea\u884c\u521b\u5efa\u5b57\u6bb5\uff1a<\/p>\n<pre>&lt;li&gt;{{ it.title }}\uff1a&lt;span v-if=\"it.sales_money\"&gt;{{ it.sales_money }}&lt;\/span&gt;&lt;\/li&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<h2>\u6574\u4f53\u4f18\u5316\u8003\u8651<\/h2>\n<ol>\n<li> <strong>\u4f7f\u7528\u66f4\u5408\u9002\u7684\u5de5\u5177\uff1a<\/strong>\u8003\u8651\u4f7f\u7528\u5177\u6709\u5c06\u6570\u636e\u6e32\u67d3\u5230 HTML \u7684\u7279\u6027\u5e93\u6216\u6846\u67b6\uff0c\u5982 Vue.js \u6216 React.js\uff0c\u51cf\u5c11\u624b\u52a8\u64cd\u4f5c\u3002<\/li>\n<li> <strong>\u4f7f\u7528\u54cd\u5e94\u5f0f\u7ed1\u5b9a\uff1a<\/strong>\u5b9e\u73b0\u53cc\u5411\u6570\u636e\u7ed1\u5b9a\uff0c\u5f53\u6570\u636e\u6e90\u53d1\u751f\u53d8\u5316\u65f6\uff0c\u9875\u9762\u5185\u5bb9\u81ea\u52a8\u66f4\u65b0\uff0c\u907f\u514d\u9891\u7e41\u7684 DOM \u64cd\u4f5c\u3002<\/li>\n<li> <strong>\u4f18\u5316\u6570\u636e\u7ed3\u6784\uff1a<\/strong>\u5bf9\u6570\u636e\u6e90\u8fdb\u884c\u5408\u7406\u7684\u8bbe\u8ba1\uff0c\u907f\u514d\u6570\u636e\u5d4c\u5957\u8fc7\u4e8e\u590d\u6742\uff0c\u4fbf\u4e8e\u67e5\u627e\u548c\u5904\u7406\u3002<\/li>\n<li> <strong>\u4f7f\u7528\u7f13\u5b58\uff1a<\/strong>\u6839\u636e\u9700\u8981\uff0c\u4f7f\u7528\u7f13\u5b58\u673a\u5236\u5b58\u50a8\u91cd\u590d\u6570\u636e\uff0c\u51cf\u5c11\u670d\u52a1\u5668\u4ea4\u4e92\u548c\u6e32\u67d3\u65f6\u95f4\u3002<\/li>\n<\/ol>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f18\u5316JS\u4ee3\u7801\u548cHTML\u4ee3\u7801\uff0c\u63d0\u5347\u6570\u636e\u5c55\u793a\u6548\u7387\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\u5c55\u793a\u6570\u636e\u4ee3\u7801 JS \u4f18\u5316 \u539f\u4ee3\u7801\u901a\u8fc7\u5d4c\u5957\u5faa\u73af\u67e5\u627e\u6570\u636e\u6e90\u4e2d\u7684\u5bf9\u5e94\u9879\uff0c\u6548\u7387\u8f83\u4f4e\u3002\u4f18\u5316\u65b9\u5f0f\u5982\u4e0b\uff1a const data = { \/* &#8230; *\/ }; dataList.flatMap(it =&gt; it.content) .forEach(it =&gt; { \/\/ \u63d0\u53d6 key const key = Object.keys(it)[0]; it.value = data[key]; }); \u767b\u5f55\u540e\u590d\u5236 \u5c06\u6241\u5e73\u5316\u5904\u7406\u540e\u7684 dataList \u4e2d\u7684\u5143\u7d20\u9010\u4e00\u904d\u5386\uff0c\u76f4\u63a5\u83b7\u53d6\u5bf9\u5e94\u7684 value\uff0c\u7701\u53bb\u591a\u5c42\u5d4c\u5957\u5faa\u73af\u3002 HTML \u4f18\u5316 \u4e3a\u6ee1\u8db3\u6e32\u67d3\u9700\u6c42\uff0c\u539f\u4ee3\u7801\u5728\u6570\u636e\u6e90\u4e2d\u6dfb\u52a0\u4e86\u65e0\u610f\u4e49\u7684 value \u5b57\u6bb5\u3002\u4f18\u5316\u65b9\u5f0f\u662f\u907f\u514d\u5c06\u65e0\u5173\u5b57\u6bb5\u6dfb\u52a0\u5230\u6570\u636e\u6e90\u4e2d\uff0c\u5728 HTML \u4e2d\u6839\u636e\u9700\u8981\u81ea\u884c\u521b\u5efa\u5b57\u6bb5\uff1a &lt;li&gt;{{ it.title }}\uff1a&lt;span v-if=&#8221;it.sales_money&#8221;&gt;{{ it.sales_money }}&lt;\/span&gt;&lt;\/li&gt; \u767b\u5f55\u540e\u590d\u5236 \u6574\u4f53\u4f18\u5316\u8003\u8651 \u4f7f\u7528\u66f4\u5408\u9002\u7684\u5de5\u5177\uff1a\u8003\u8651\u4f7f\u7528\u5177\u6709\u5c06\u6570\u636e\u6e32\u67d3\u5230 HTML \u7684\u7279\u6027\u5e93\u6216\u6846\u67b6\uff0c\u5982 Vue.js \u6216 React.js\uff0c\u51cf\u5c11\u624b\u52a8\u64cd\u4f5c\u3002 [&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-1295","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1295","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=1295"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1295\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=1295"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=1295"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=1295"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}