{"id":27878,"date":"2024-11-24T09:21:53","date_gmt":"2024-11-24T01:21:53","guid":{"rendered":"https:\/\/fwq.ai\/blog\/27878\/"},"modified":"2024-11-24T09:21:53","modified_gmt":"2024-11-24T01:21:53","slug":"%e5%9c%a8-react-%e4%b8%ad%ef%bc%8c%e5%a6%82%e4%bd%95%e4%b8%ba-map-%e5%be%aa%e7%8e%af%e5%88%9b%e5%bb%ba%e7%9a%84-div-%e6%b7%bb%e5%8a%a0%e8%a1%8c%e5%8f%b7%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/27878\/","title":{"rendered":"\u5728 React \u4e2d\uff0c\u5982\u4f55\u4e3a map \u5faa\u73af\u521b\u5efa\u7684 div \u6dfb\u52a0\u884c\u53f7\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173132749459985.jpg\" class=\"aligncenter\" title=\"\u5728 React \u4e2d\uff0c\u5982\u4f55\u4e3a map \u5faa\u73af\u521b\u5efa\u7684 div \u6dfb\u52a0\u884c\u53f7\uff1f\u63d2\u56fe\" alt=\"\u5728 React \u4e2d\uff0c\u5982\u4f55\u4e3a map \u5faa\u73af\u521b\u5efa\u7684 div \u6dfb\u52a0\u884c\u53f7\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5728 react \u4e2d\u4e3a map \u5faa\u73af\u521b\u5efa\u7684 div \u6dfb\u52a0\u884c\u53f7<\/strong><\/p>\n<p>\u4e3a\u4e86\u7ed9\u5faa\u73af\u521b\u5efa\u7684 div \u6dfb\u52a0\u884c\u53f7\uff0c\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u65b9\u6848\uff1a<\/p>\n<p>\u9996\u5148\uff0c\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u4f5c\u4e3a\u884c\u53f7\u5bb9\u5668\u7684 div\uff0c\u8bbe\u7f6e\u5176 position \u4e3a absolute\uff0c\u5e76\u653e\u7f6e\u5728\u5de6\u4fa7\u3002\u7136\u540e\uff0c\u5c06\u5faa\u73af\u521b\u5efa\u7684 div \u8bbe\u7f6e position \u4e3a relative\uff0c\u5e76\u8bbe\u7f6e\u7236\u5143\u7d20\u4e3a : hidden\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u53ef\u4ee5\u5c06\u884c\u53f7\u7f6e\u4e8e div \u7684\u5de6\u4fa7\u3002<\/p>\n<p>\u5177\u4f53\u5b9e\u73b0\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>\/\/ index.js\nimport 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> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<pre>\/\/ styles.css\n.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> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5728 React \u4e2d\uff0c\u5982\u4f55\u4e3a map \u5faa\u73af\u521b\u5efa\u7684 div \u6dfb\u52a0\u884c\u53f7\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>\u5728 react \u4e2d\u4e3a map \u5faa\u73af\u521b\u5efa\u7684 div \u6dfb\u52a0\u884c\u53f7 \u4e3a\u4e86\u7ed9\u5faa\u73af\u521b\u5efa\u7684 div \u6dfb\u52a0\u884c\u53f7\uff0c\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u65b9\u6848\uff1a \u9996\u5148\uff0c\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u4f5c\u4e3a\u884c\u53f7\u5bb9\u5668\u7684 div\uff0c\u8bbe\u7f6e\u5176 position \u4e3a absolute\uff0c\u5e76\u653e\u7f6e\u5728\u5de6\u4fa7\u3002\u7136\u540e\uff0c\u5c06\u5faa\u73af\u521b\u5efa\u7684 div \u8bbe\u7f6e position \u4e3a relative\uff0c\u5e76\u8bbe\u7f6e\u7236\u5143\u7d20\u4e3a : hidden\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u53ef\u4ee5\u5c06\u884c\u53f7\u7f6e\u4e8e div \u7684\u5de6\u4fa7\u3002 \u5177\u4f53\u5b9e\u73b0\u4ee3\u7801\u5982\u4e0b\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 [&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-27878","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27878","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=27878"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27878\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=27878"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=27878"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=27878"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}