{"id":52693,"date":"2024-12-03T08:14:16","date_gmt":"2024-12-03T00:14:16","guid":{"rendered":"https:\/\/fwq.ai\/blog\/52693\/"},"modified":"2024-12-03T08:14:16","modified_gmt":"2024-12-03T00:14:16","slug":"react%e7%bb%84%e4%bb%b6%e4%b8%ad%e5%a6%82%e4%bd%95%e4%b8%bamap%e5%be%aa%e7%8e%af%e7%94%9f%e6%88%90%e7%9a%84div%e5%85%83%e7%b4%a0%e6%b7%bb%e5%8a%a0%e8%a1%8c%e5%8f%b7%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/52693\/","title":{"rendered":"React\u7ec4\u4ef6\u4e2d\u5982\u4f55\u4e3amap\u5faa\u73af\u751f\u6210\u7684div\u5143\u7d20\u6dfb\u52a0\u884c\u53f7\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>React\u7ec4\u4ef6\u4e2d\u5982\u4f55\u4e3amap\u5faa\u73af\u751f\u6210\u7684div\u5143\u7d20\u6dfb\u52a0\u884c\u53f7\uff1f<\/h1>\n<p>\u79ef\u7d2f\u77e5\u8bc6\uff0c\u80dc\u8fc7\u79ef\u84c4\u91d1\u94f6\uff01\u6bd5\u7adf\u5728\u6587\u7ae0\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4f1a\u9047\u5230\u5404\u79cd\u5404\u6837\u7684\u95ee\u9898\uff0c\u5f80\u5f80\u90fd\u662f\u4e00\u4e9b\u7ec6\u8282\u77e5\u8bc6\u70b9\u8fd8\u6ca1\u6709\u638c\u63e1\u597d\u800c\u5bfc\u81f4\u7684\uff0c\u56e0\u6b64\u57fa\u7840\u77e5\u8bc6\u70b9\u7684\u79ef\u7d2f\u662f\u5f88\u91cd\u8981\u7684\u3002\u4e0b\u9762\u672c\u6587\u300aReact\u7ec4\u4ef6\u4e2d\u5982\u4f55\u4e3amap\u5faa\u73af\u751f\u6210\u7684div\u5143\u7d20\u6dfb\u52a0\u884c\u53f7\uff1f\u300b\uff0c\u5c31\u5e26\u5927\u5bb6\u8bb2\u89e3\u4e00\u4e0b\u77e5\u8bc6\u70b9\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241122\/173227071867405a7eba64d.jpg\" class=\"aligncenter\" title=\"React\u7ec4\u4ef6\u4e2d\u5982\u4f55\u4e3amap\u5faa\u73af\u751f\u6210\u7684div\u5143\u7d20\u6dfb\u52a0\u884c\u53f7\uff1f\u63d2\u56fe\" alt=\"React\u7ec4\u4ef6\u4e2d\u5982\u4f55\u4e3amap\u5faa\u73af\u751f\u6210\u7684div\u5143\u7d20\u6dfb\u52a0\u884c\u53f7\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u7ed9 react \u7ec4\u4ef6\u521b\u5efa\u7684 div \u884c\u53f7<\/strong><\/p>\n<p>\u8981\u7ed9\u4f7f\u7528 map \u5faa\u73af\u521b\u5efa\u7684 div \u6dfb\u52a0\u884c\u53f7\uff0c\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u8bbe\u8ba1\u65b9\u6848\uff1a<\/p>\n<p>\u5de6\u4fa7\u7684\u7d22\u5f15\u5143\u7d20\u8bbe\u7f6e\u7edd\u5bf9\u5b9a\u4f4d\uff08absolute\uff09\uff0c\u53f3\u4fa7\u7684\u65b9\u5757\u8bbe\u7f6e\u76f8\u5bf9\u5b9a\u4f4d\uff08relative\uff09\uff0c\u4e24\u8005\u7684\u7236\u5143\u7d20\u8bbe\u7f6e\u76f8\u5bf9\u5b9a\u4f4d\u548c\u6ea2\u51fa\u9690\u85cf\uff08overflow: hidden\uff09\u3002<\/p>\n<p>\u4ee3\u7801\u793a\u4f8b\uff1a<\/p>\n<p><strong>index.js<\/strong><\/p>\n<pre>import react from \"react\";\nimport reactdom from \"react-dom\";\nimport \".\/styles.css\";\n\nfunction app() {\n  const itemdata = new array(500).fill(0);\n  const indexdata = new array(20).fill(0);\n\n  return (\n    &lt;div classname=\"app\"&gt;\n      &lt;div classname=\"left-box\"&gt;\n        {indexdata.map((item, index) =&gt; (\n          &lt;div\n            key={index}\n            style={{\n              fontsize: \"9px\",\n              width: \"19px\",\n              height: \"20px\",\n              margin: \"2px\",\n            }}\n          &gt;\n            {index + 1}\n          &lt;\/div&gt;\n        ))}\n      &lt;\/div&gt;\n      &lt;div classname=\"right-box\"&gt;\n        {itemdata.map((item, index) =&gt; (\n          &lt;div\n            key={index}\n            style={{\n              display: \"inline-block\",\n              width: \"9px\",\n              height: \"9px\",\n              margin: \"2px\",\n              backgroundcolor: item.selected ? \"green\" : \"lightgreen\",\n            }}\n          &gt;&lt;\/div&gt;\n        ))}\n      &lt;\/div&gt;\n    &lt;\/div&gt;\n  );\n}\n\nconst rootelement = document.getelementbyid(\"root\");\nreactdom.render(&lt;app \/&gt;, rootelement);<\/pre>\n<p><strong>styles.css<\/strong><\/p>\n<pre>.App {\n  font-family: sans-serif;\n  text-align: center;\n  overflow: hidden;\n  position: relative;\n}\n\n.left-box {\n  position: absolute;\n  left: 0;\n  top: 0;\n\n  width: 19px;\n  overflow: hidden;\n}\n\n.right-box {\n  margin-left: 19px;\n}<\/pre>\n<p>\u901a\u8fc7\u8fd9\u79cd\u8bbe\u8ba1\uff0c\u53ef\u4ee5\u5b9e\u73b0\u4f7f\u7528 map \u5faa\u73af\u521b\u5efa\u7684 div \u884c\u53f7\u6548\u679c\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\u7c73\u4e91\uff01\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u3002<\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   \u4e3a\u4ec0\u4e48 Vue.js \u4e2d\u52a8\u6001\u53d8\u66f4\u6807\u7b7e\u6837\u5f0f\u65e0\u6548\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>React\u7ec4\u4ef6\u4e2d\u5982\u4f55\u4e3amap\u5faa\u73af\u751f\u6210\u7684div\u5143\u7d20\u6dfb\u52a0\u884c\u53f7\uff1f \u79ef\u7d2f\u77e5\u8bc6\uff0c\u80dc\u8fc7\u79ef\u84c4\u91d1\u94f6\uff01\u6bd5\u7adf\u5728\u6587\u7ae0\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4f1a\u9047\u5230\u5404\u79cd\u5404\u6837\u7684\u95ee\u9898\uff0c\u5f80\u5f80\u90fd\u662f\u4e00\u4e9b\u7ec6\u8282\u77e5\u8bc6\u70b9\u8fd8\u6ca1\u6709\u638c\u63e1\u597d\u800c\u5bfc\u81f4\u7684\uff0c\u56e0\u6b64\u57fa\u7840\u77e5\u8bc6\u70b9\u7684\u79ef\u7d2f\u662f\u5f88\u91cd\u8981\u7684\u3002\u4e0b\u9762\u672c\u6587\u300aReact\u7ec4\u4ef6\u4e2d\u5982\u4f55\u4e3amap\u5faa\u73af\u751f\u6210\u7684div\u5143\u7d20\u6dfb\u52a0\u884c\u53f7\uff1f\u300b\uff0c\u5c31\u5e26\u5927\u5bb6\u8bb2\u89e3\u4e00\u4e0b\u77e5\u8bc6\u70b9\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~ \u7ed9 react \u7ec4\u4ef6\u521b\u5efa\u7684 div \u884c\u53f7 \u8981\u7ed9\u4f7f\u7528 map \u5faa\u73af\u521b\u5efa\u7684 div \u6dfb\u52a0\u884c\u53f7\uff0c\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u8bbe\u8ba1\u65b9\u6848\uff1a \u5de6\u4fa7\u7684\u7d22\u5f15\u5143\u7d20\u8bbe\u7f6e\u7edd\u5bf9\u5b9a\u4f4d\uff08absolute\uff09\uff0c\u53f3\u4fa7\u7684\u65b9\u5757\u8bbe\u7f6e\u76f8\u5bf9\u5b9a\u4f4d\uff08relative\uff09\uff0c\u4e24\u8005\u7684\u7236\u5143\u7d20\u8bbe\u7f6e\u76f8\u5bf9\u5b9a\u4f4d\u548c\u6ea2\u51fa\u9690\u85cf\uff08overflow: hidden\uff09\u3002 \u4ee3\u7801\u793a\u4f8b\uff1a index.js import react from &#8220;react&#8221;; import reactdom from &#8220;react-dom&#8221;; import &#8220;.\/styles.css&#8221;; function app() { const itemdata = new array(500).fill(0); const indexdata = new array(20).fill(0); return ( &lt;div classname=&#8221;app&#8221;&gt; &lt;div classname=&#8221;left-box&#8221;&gt; {indexdata.map((item, index) =&gt; ( &lt;div key={index} style={{ fontsize: &#8220;9px&#8221;, width: [&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-52693","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52693","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=52693"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52693\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=52693"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=52693"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=52693"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}