{"id":299,"date":"2021-09-22T20:55:27","date_gmt":"2021-09-22T12:55:27","guid":{"rendered":"http:\/\/gjweb.top\/?p=299"},"modified":"2021-09-22T20:55:28","modified_gmt":"2021-09-22T12:55:28","slug":"%e6%9d%a1%e4%bb%b6%e6%b8%b2%e6%9f%93%e5%92%8c%e5%88%97%e8%a1%a8%e6%b8%b2%e6%9f%93","status":"publish","type":"post","link":"https:\/\/gjweb.top\/?p=299","title":{"rendered":"\u6761\u4ef6\u6e32\u67d3\u548c\u5217\u8868\u6e32\u67d3"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>import React from \"react\"<br>class Hello extends React.Component{<br> &nbsp; &nbsp;constructor(props){<br> &nbsp; &nbsp; &nbsp; &nbsp;supre(props)<br> &nbsp; &nbsp; &nbsp; &nbsp;this.state = {<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;data:&#91;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  {name:\"zhangsan\",age:18},<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  {name:\"lisi\",age:20},<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  {name:\"wangwu\",age:21}<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  ]<br> &nbsp; &nbsp; &nbsp;  }<br> &nbsp;  }<br> &nbsp; &nbsp;\/*\u6761\u4ef6\u6e32\u67d3*\/<br> &nbsp; &nbsp;render = ()=&gt;{<br> &nbsp; &nbsp; &nbsp; &nbsp;let renderHtml = \"\";<br> &nbsp; &nbsp; &nbsp; &nbsp;if(this.state.data.length === 0){<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;renderHtml = (<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;      &lt;div&gt;\u6682\u65e0\u6570\u636e&lt;\/div&gt;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  )<br> &nbsp; &nbsp; &nbsp;  }else{<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\/*\u5217\u8868\u6e32\u67d3*\/<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;renderHtml = (<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;      &lt;ul&gt;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;      {<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.state.data.map((item,index)=&gt;{<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;              return(&lt;li key={index}&gt;{item.name}:{item.age}&lt;\/li&gt;)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;              })<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;\/ul&gt;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  )<br> &nbsp; &nbsp; &nbsp;  }<br> &nbsp;  }<br> &nbsp; &nbsp;render(){<br> &nbsp; &nbsp; &nbsp; &nbsp;return(<br> &nbsp; &nbsp; &nbsp;      &lt;div&gt;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;      {this.render()}<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;\/div&gt;<br> &nbsp; &nbsp; &nbsp;  )<br> &nbsp;  }<br>}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28],"tags":[],"class_list":["post-299","post","type-post","status-publish","format-standard","hentry","category-react"],"_links":{"self":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/299","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=299"}],"version-history":[{"count":0,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/299\/revisions"}],"wp:attachment":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=299"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=299"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=299"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}