Ver Fonte

Listing 10: iterating on comments dynamically.

Frederic G. MARAND há 8 anos atrás
pai
commit
5de792278e
1 ficheiros alterados com 8 adições e 2 exclusões
  1. 8 2
      public/scripts/tutorial.js

+ 8 - 2
public/scripts/tutorial.js

@@ -22,10 +22,16 @@ let Comment = React.createClass({
 
 let CommentList = React.createClass({
   render: function () {
+    let commentNodes = this.props.data.map(function (comment) {
+      return (
+        <Comment author={comment.author} key={comment.id}>
+          {comment.text}
+        </Comment>
+      );
+    });
     return (
       <div className="commentList">
-        <Comment author="Pete Hunt">This is one comment</Comment>
-        <Comment author="Jordan Walke">This is *another* comment</Comment>
+        {commentNodes}
         </div>
     );
   }