A
A
Albert Tobacco2015-04-09 17:36:27
JavaScript
Albert Tobacco, 2015-04-09 17:36:27

Render not an array but a ReactJS object?

Having heard a lot of fables about how good React is, I decided to try it. I ran into a problem
in the tutorial there is an example

// tutorial10.js
var CommentList = React.createClass({
  render: function() {
    var commentNodes = this.props.data.map(function (comment) {
      return (
        <Comment author={comment.author}>
          {comment.text}
        </Comment>
      );
    });
    return (
      <div className="commentList">
        {commentNodes}
      </div>
    );
  }
});

But what if I don’t have an array there, but an object, how can I render it in a similar way? already perverted both through $.each and through for( var in ) . nothing is obtained.
I will be really grateful for your help

Answer the question

In order to leave comments, you need to log in

1 answer(s)
1
123 123, 2015-04-09
@bighoc

Object.keys(obj).map(key => obj[key].author); // returns array of author names

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question