{"id":6520,"date":"2023-01-08T21:29:08","date_gmt":"2023-01-08T13:29:08","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=6520"},"modified":"2023-01-08T21:29:08","modified_gmt":"2023-01-08T13:29:08","slug":"%e4%bd%bf%e7%94%a8react-js%e5%88%a4%e6%96%b7%e5%a5%87%e6%95%b8%e7%9a%84%e6%96%b9%e6%b3%95-2","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/react-js\/%e4%bd%bf%e7%94%a8react-js%e5%88%a4%e6%96%b7%e5%a5%87%e6%95%b8%e7%9a%84%e6%96%b9%e6%b3%95-2\/","title":{"rendered":"\u4f7f\u7528React.JS\u5224\u65b7\u5947\u6578\u7684\u65b9\u6cd5"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"React, React List, isOdd\"><\/p>\n<h1>\u4f7f\u7528 React.JS \u5224\u65b7 React List \u662f\u5426\u70ba\u5947\u6570(isOdd)<\/h1>\n<p>React.JS \u662f\u4e00\u500b\u7528\u65bc\u69cb\u5efa\u7528\u6236\u754c\u9762\u7684 JavaScript \u5eab\uff0c\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5feb\u901f\u69cb\u5efa\u51fa\u9ad8\u54c1\u8cea\u7684\u7528\u6236\u754c\u9762\u3002\u5728 React.JS \u4e2d\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u4f7f\u7528 React List \u4f86\u5275\u5efa\u4e00\u500b\u5217\u8868\uff0c\u4e26\u4e14\u53ef\u4ee5\u4f7f\u7528 isOdd \u51fd\u6578\u4f86\u5224\u65b7\u5217\u8868\u4e2d\u7684\u5143\u7d20\u662f\u5426\u70ba\u5947\u6578\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u5728 React.JS \u4e2d\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u4f7f\u7528 <code>React.createElement()<\/code> \u4f86\u5275\u5efa\u4e00\u500b React List\uff0c\u4e26\u4e14\u53ef\u4ee5\u4f7f\u7528 <code>React.Children.map()<\/code> \u4f86\u5c0d\u5217\u8868\u4e2d\u7684\u5143\u7d20\u9032\u884c\u904d\u6b77\u3002\u5728\u904d\u6b77\u7684\u904e\u7a0b\u4e2d\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u4f7f\u7528 <code>isOdd()<\/code> \u51fd\u6578\u4f86\u5224\u65b7\u5217\u8868\u4e2d\u7684\u5143\u7d20\u662f\u5426\u70ba\u5947\u6578\u3002<\/p>\n<pre class=\"brush: javascript\">\nconst isOdd = (num) => {\n  return num % 2 !== 0;\n};\n\nconst list = React.createElement(\n  'ul',\n  null,\n  React.Children.map(list, (item, index) => {\n    return React.createElement(\n      'li',\n      { key: index },\n      isOdd(item) ? '\u5947\u6578' : '\u5076\u6578'\n    );\n  })\n);\n<\/pre>\n<p>\u4e0a\u9762\u7684\u7a0b\u5f0f\u78bc\u4e2d\uff0c\u6211\u5011\u4f7f\u7528 <code>isOdd()<\/code> \u51fd\u6578\u4f86\u5224\u65b7\u5217\u8868\u4e2d\u7684\u5143\u7d20\u662f\u5426\u70ba\u5947\u6578\uff0c\u5982\u679c\u662f\u5947\u6578\uff0c\u5247\u5c07\u5176\u8a2d\u7f6e\u70ba\u201c\u5947\u6578\u201d\uff0c\u5426\u5247\u8a2d\u7f6e\u70ba\u201c\u5076\u6578\u201d\u3002<\/p>\n<p>\u4f7f\u7528 React.JS \u4f86\u5224\u65b7 React List \u662f\u5426\u70ba\u5947\u6578(isOdd)\uff0c\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u52a0\u5feb\u901f\u3001\u9748\u6d3b\u5730\u69cb\u5efa\u51fa\u9ad8\u54c1\u8cea\u7684\u7528\u6236\u754c\u9762\u3002\u5982\u679c\u4f60\u60f3\u8981\u5b78\u7fd2\u66f4\u591a\u95dc\u65bc React.JS \u7684\u77e5\u8b58\uff0c\u6b61\u8fce\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\uff0c\u6211\u5011\u6703\u63d0\u4f9b\u66f4\u591a\u7684\u5b78\u7fd2\u8cc7\u6e90\u7d66\u4f60\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528React.JS\u7684isOdd()\u51fd\u6578\u4f86\u5224\u65b7\u4e00\u500b\u6578\u5b57\u662f\u5426\u70ba\u5947\u6578\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u7c21\u55ae\u7684\u7bc4\u4f8b\u4f86\u8a73\u7d30\u8aaa\u660e\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[184,183],"tags":[182,181],"class_list":["post-6520","post","type-post","status-publish","format-standard","hentry","category-react","category-react-js","tag-react","tag-react-js"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1Ha","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6520","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=6520"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6520\/revisions"}],"predecessor-version":[{"id":6521,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6520\/revisions\/6521"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=6520"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=6520"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=6520"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}