{"id":5749,"date":"2023-01-06T14:53:37","date_gmt":"2023-01-06T06:53:37","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=5749"},"modified":"2023-01-06T14:53:37","modified_gmt":"2023-01-06T06:53:37","slug":"%e4%bd%bf%e7%94%a8react-js%e5%bf%ab%e9%80%9f%e6%aa%a2%e6%9f%a5%e6%95%b8%e5%ad%97%e6%98%af%e5%90%a6%e7%82%ba%e5%81%b6%e6%95%b0","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/react-js\/%e4%bd%bf%e7%94%a8react-js%e5%bf%ab%e9%80%9f%e6%aa%a2%e6%9f%a5%e6%95%b8%e5%ad%97%e6%98%af%e5%90%a6%e7%82%ba%e5%81%b6%e6%95%b0\/","title":{"rendered":"\u4f7f\u7528React.JS\u5feb\u901f\u6aa2\u67e5\u6578\u5b57\u662f\u5426\u70ba\u5076\u6570"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"React, React List, isEven\"><\/p>\n<h1>\u4f7f\u7528 React.JS \u5224\u65b7 React List \u4e2d\u7684\u6578\u5b57\u662f\u5426\u70ba\u5076\u6570(isEven)<\/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\u66f4\u8f15\u9b06\u5730\u69cb\u5efa\u9ad8\u6027\u80fd\u7684\u7db2\u9801\u61c9\u7528\u7a0b\u5e8f\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 isEven \u51fd\u6578\u4f86\u5224\u65b7\u5217\u8868\u4e2d\u7684\u6578\u5b57\u662f\u5426\u70ba\u5076\u6570\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\u6bcf\u500b\u5143\u7d20\u9032\u884c\u904d\u6b77\u3002\u4f8b\u5982\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u7a0b\u5f0f\u78bc\u4f86\u5275\u5efa\u4e00\u500b React List\uff1a<\/p>\n<pre class=\"brush: javascript\">\nconst list = React.createElement(\n  'ul',\n  null,\n  React.Children.map([1, 2, 3, 4], (item) => {\n    return React.createElement('li', null, item);\n  })\n);\n<\/pre>\n<p>\u4e0a\u9762\u7684\u7a0b\u5f0f\u78bc\u6703\u5275\u5efa\u4e00\u500b\u5305\u542b\u56db\u500b\u5143\u7d20\u7684 React List\uff0c\u6bcf\u500b\u5143\u7d20\u7684\u503c\u5206\u5225\u70ba 1\u30012\u30013 \u548c 4\u3002<\/p>\n<p>\u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528 <code>isEven()<\/code> \u51fd\u6578\u4f86\u5224\u65b7 React List \u4e2d\u7684\u6578\u5b57\u662f\u5426\u70ba\u5076\u6570\uff1a<\/p>\n<pre class=\"brush: javascript\">\nconst isEven = (list) => {\n  return React.Children.map(list, (item) => {\n    return item % 2 === 0;\n  });\n};\n<\/pre>\n<p>\u4e0a\u9762\u7684\u7a0b\u5f0f\u78bc\u6703\u5c0d React List \u4e2d\u7684\u6bcf\u500b\u5143\u7d20\u9032\u884c\u904d\u6b77\uff0c\u4e26\u4e14\u5224\u65b7\u8a72\u5143\u7d20\u662f\u5426\u70ba\u5076\u6570\uff0c\u5982\u679c\u662f\u5076\u6570\u5247\u8fd4\u56de <code>true<\/code>\uff0c\u5426\u5247\u8fd4\u56de <code>false<\/code>\u3002<\/p>\n<p>\u7e3d\u7d50\uff0c\u4f7f\u7528 React.JS \u4e2d\u7684 React List \u548c isEven \u51fd\u6578\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u8f15\u9b06\u5730\u5224\u65b7 React List \u4e2d\u7684\u6578\u5b57\u662f\u5426\u70ba\u5076\u6570\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981\uff1a\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528React.JS\u5feb\u901f\u6aa2\u67e5\u6578\u5b57\u662f\u5426\u70ba\u5076\u6570\uff0c\u4e26\u4ecb\u7d39ReactList\u4e2d\u7684isEven()\u51fd\u6578\u529f\u80fd\uff0c\u8b93\u5b78\u751f\u53ef\u4ee5\u5feb\u901f\u6aa2\u67e5\u6578\u5b57\u662f\u5426\u70ba\u5076\u6570\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-5749","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-1uJ","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5749","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=5749"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5749\/revisions"}],"predecessor-version":[{"id":5750,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5749\/revisions\/5750"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=5749"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=5749"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=5749"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}