kal*_*kar 0 sorting mapping reactjs react-native
constructor(props) {
super(props);
let comments = [{body: "good", created_at:"2018-02-12T05:27:47.175Z"},
{body: "bad article", created_at:"2017-11-12T05:27:47.175Z"},
{body: "great", created_at:"2017-10-12T05:27:47.175Z"}];
this.state = { comments };
render() {
return(
{ comments.map((comment, index) =>
<Text>{comment.body}</Text>
)}
);
};
Run Code Online (Sandbox Code Playgroud)
数据按降序排列,但我想根据created_at
日期按升序排序.
现在,新的评论首先出现,并且想要先老的评语.
我该如何对此评论进行排序?请建议任何解决方案.
添加.reverse()
后map
.
comments.map((comment, index) =>
<Text>{comment.body}</Text>
).reverse();
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
673 次 |
最近记录: |