世博会提取显示相反的结果



我和我的团队正在研究世博会的获取方法,它看起来像这样。

export function getCalendarEvents() {
return fetch('http://50520dbf.ngrok.io/api/v1/events/date/')
.then((response) => response.json())
.then((responseJson) => {
this.setState({
isLoaded: true,
dataSource: responseJson,
}, function () {
});
})
.catch((error) => {
console.error(error);
});
}

基于此方法,它按此顺序返回以下值

[ 
{ 
"feedbackLogId":4,
"time":"3 Weeks Ago",
"recipient":"10060878",
"type":"Compliment",
"sender":"10060878",
"imageUrl":"",
"name":"AUNG THU"
},
{ 
"feedbackLogId":5,
"time":"1 Weeks Ago",
"recipient":"10060878",
"type":"Compliment",
"sender":"10060878",
"imageUrl":"",
"name":"JUN HAO 3"
}
]

有没有办法可以反转获取的顺序,使其像这样以相反的方式返回?

[ 
{ 
"feedbackLogId":5,
"time":"1 Weeks Ago",
"recipient":"10060878",
"type":"Compliment",
"sender":"10059046",
"imageUrl":"",
"name":"JUN HAO 3"
},
{ 
"feedbackLogId":4,
"time":"3 Weeks Ago",
"recipient":"10060273",
"type":"Compliment",
"sender":"10059046",
"imageUrl":"",
"name":"AUNG THU"
}
]

感谢您的帮助和欢呼:)

您可以通过显式反转数组响应来轻松做到这一点。Lodash 形式的reverse功能可以帮助您实现这一目标。

你的代码将成为。

import { reverse } from 'lodash';
...
this.setState({
isLoaded: true,
dataSource: reverse(responseJson),
}, function () {
...

最新更新