【发布时间】:2015-06-30 05:31:26
【问题描述】:
我有一个带有根节点的 json:
{
"comments":
[
{"id":1,"author_name":null,"comment_text":null,"url":"http://localhost:3000/comments/1.json"}
]
}
我想遍历每个对象。 这是我尝试的:
var commentNodes = this.props.comments.map(function(comment,index){
// do something over each object
);
});
但它不起作用:
Uncaught TypeError: this.props.comments.map is not a function
【问题讨论】:
-
你是如何定义变量
this.props的? -
@TaoP.R.,忘了说,这其实是 React。
-
映射用于数组而非对象。
标签: javascript json reactjs