{"id":5785,"date":"2023-01-06T15:00:16","date_gmt":"2023-01-06T07:00:16","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=5785"},"modified":"2023-01-06T15:00:16","modified_gmt":"2023-01-06T07:00:16","slug":"%e4%bd%bf%e7%94%a8react-js%e6%b1%82%e5%8f%96%e5%8d%94%e6%96%b9%e5%b7%ae%ef%bc%9a%e4%b8%80%e5%80%8b%e7%b0%a1%e5%96%ae%e7%9a%84%e6%8c%87%e5%8d%97","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/react-js\/%e4%bd%bf%e7%94%a8react-js%e6%b1%82%e5%8f%96%e5%8d%94%e6%96%b9%e5%b7%ae%ef%bc%9a%e4%b8%80%e5%80%8b%e7%b0%a1%e5%96%ae%e7%9a%84%e6%8c%87%e5%8d%97\/","title":{"rendered":"\u4f7f\u7528React.JS\u6c42\u53d6\u5354\u65b9\u5dee\uff1a\u4e00\u500b\u7c21\u55ae\u7684\u6307\u5357"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"React, List, Covariance\"><\/p>\n<h1>\u4f7f\u7528 React.JS \u6c42\u534f\u65b9\u5dee(covariance)<\/h1>\n<p>\u534f\u65b9\u5dee(covariance)\u662f\u4e00\u7a2e\u7d71\u8a08\u6280\u8853\uff0c\u7528\u65bc\u8861\u91cf\u5169\u500b\u8b8a\u91cf\u4e4b\u9593\u7684\u7dda\u6027\u95dc\u4fc2\u3002\u5b83\u53ef\u4ee5\u7528\u4f86\u6e2c\u91cf\u5169\u500b\u8b8a\u91cf\u4e4b\u9593\u7684\u76f8\u95dc\u6027\uff0c\u4e26\u4e14\u53ef\u4ee5\u7528\u4f86\u9810\u6e2c\u5169\u500b\u8b8a\u91cf\u4e4b\u9593\u7684\u8b8a\u5316\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528 React.JS \u4f86\u6c42\u53d6\u5354\u65b9\u5dee\u3002<\/p>\n<h2>\u4f7f\u7528 React.JS \u6c42\u53d6\u5354\u65b9\u5dee<\/h2>\n<p>React.JS \u662f\u4e00\u500b JavaScript \u6846\u67b6\uff0c\u53ef\u4ee5\u7528\u65bc\u958b\u767c\u9ad8\u6027\u80fd\u7684 Web \u548c\u79fb\u52d5\u61c9\u7528\u7a0b\u5e8f\u3002\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5feb\u901f\u958b\u767c\u548c\u90e8\u7f72\u61c9\u7528\u7a0b\u5e8f\uff0c\u4e26\u4e14\u53ef\u4ee5\u63d0\u4f9b\u9ad8\u6027\u80fd\u7684\u7528\u6236\u9ad4\u9a57\u3002<\/p>\n<p>React.JS \u63d0\u4f9b\u4e86\u4e00\u500b List \u7d44\u4ef6\uff0c\u53ef\u4ee5\u7528\u65bc\u6c42\u53d6\u5354\u65b9\u5dee\u3002List \u7d44\u4ef6\u53ef\u4ee5\u63a5\u53d7\u4e00\u500b\u6578\u7d44\uff0c\u4e26\u5c07\u5176\u8f49\u63db\u70ba\u4e00\u500b React \u5143\u7d20\u7684\u5217\u8868\u3002\u5b83\u53ef\u4ee5\u63a5\u53d7\u4e00\u500b\u51fd\u6578\u4f5c\u70ba\u53c3\u6578\uff0c\u8a72\u51fd\u6578\u53ef\u4ee5\u7528\u65bc\u8a08\u7b97\u5354\u65b9\u5dee\u3002<\/p>\n<pre class=\"brush: javascript\">\nconst List = React.createClass({\n  render() {\n    const covariance = (arr1, arr2) => {\n      let sum1 = 0;\n      let sum2 = 0;\n      let sum3 = 0;\n      for (let i = 0; i < arr1.length; i++) {\n        sum1 += arr1[i] * arr2[i];\n        sum2 += arr1[i];\n        sum3 += arr2[i];\n      }\n      const n = arr1.length;\n      const cov = (sum1 - (sum2 * sum3) \/ n) \/ n;\n      return cov;\n    };\n    return (\n      <div>\n        {this.props.data.map(item => (\n          <div>\n            {covariance(item.arr1, item.arr2)}\n          <\/div>\n        ))}\n      <\/div>\n    );\n  }\n});\n<\/pre>\n<p>\u4e0a\u9762\u7684\u7a0b\u5f0f\u78bc\u4f7f\u7528 List \u7d44\u4ef6\u4f86\u6c42\u53d6\u5354\u65b9\u5dee\u3002\u5b83\u63a5\u53d7\u4e00\u500b\u6578\u7d44\u4f5c\u70ba\u53c3\u6578\uff0c\u4e26\u5c07\u5176\u8f49\u63db\u70ba\u4e00\u500b React \u5143\u7d20\u7684\u5217\u8868\u3002\u5b83\u9084\u63a5\u53d7\u4e00\u500b\u51fd\u6578\u4f5c\u70ba\u53c3\u6578\uff0c\u8a72\u51fd\u6578\u53ef\u4ee5\u7528\u65bc\u8a08\u7b97\u5354\u65b9\u5dee\u3002<\/p>\n<p>List \u7d44\u4ef6\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5feb\u901f\u6c42\u53d6\u5354\u65b9\u5dee\uff0c\u4e26\u4e14\u53ef\u4ee5\u63d0\u4f9b\u9ad8\u6027\u80fd\u7684\u7528\u6236\u9ad4\u9a57\u3002\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5feb\u901f\u958b\u767c\u548c\u90e8\u7f72\u61c9\u7528\u7a0b\u5e8f\uff0c\u4e26\u4e14\u53ef\u4ee5\u63d0\u4f9b\u9ad8\u6027\u80fd\u7684\u7528\u6236\u9ad4\u9a57\u3002<\/p>\n<p><!--more--><\/p>\n<h2>\u7e3d\u7d50<\/h2>\n<p>\u672c\u6587\u4ecb\u7d39\u4e86\u5982\u4f55\u4f7f\u7528 React.JS \u4f86\u6c42\u53d6\u5354\u65b9\u5dee\u3002\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5feb\u901f\u958b\u767c\u548c\u90e8\u7f72\u61c9\u7528\u7a0b\u5e8f\uff0c\u4e26\u4e14\u53ef\u4ee5\u63d0\u4f9b\u9ad8\u6027\u80fd\u7684\u7528\u6236\u9ad4\u9a57\u3002List \u7d44\u4ef6\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5feb\u901f\u6c42\u53d6\u5354\u65b9\u5dee\uff0c\u4e26\u4e14\u53ef\u4ee5\u63d0\u4f9b\u9ad8\u6027\u80fd\u7684\u7528\u6236\u9ad4\u9a57\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981\uff1a\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528React.JS\u6c42\u53d6\u5354\u65b9\u5dee\uff0c\u4e26\u63d0\u4f9b\u4e00\u500b\u7c21\u55ae\u7684\u6307\u5357\uff0c\u8b93\u8b80\u8005\u53ef\u4ee5\u8f15\u9b06\u5730\u5b78\u7fd2\u5982\u4f55\u4f7f\u7528React.JS\u6c42\u53d6\u5354\u65b9\u5dee\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-5785","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-1vj","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5785","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=5785"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5785\/revisions"}],"predecessor-version":[{"id":5786,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5785\/revisions\/5786"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=5785"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=5785"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=5785"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}