gpt4 book ai didi

javascript - 我如何按最近创建的列表列出提要中的帖子?

转载 作者:太空狗 更新时间:2023-10-29 17:59:08 26 4
gpt4 key购买 nike

我的后端使用 Onymos。当我从 onymos 中提取数据时,它为我提供了一个“排列方式”属性,我可以在其中指定“createdTime”作为值,但是,由于某种原因,这不会转移到我的模板中。从我的谷歌搜索中,我认为不再有按指令排序的 Angular 。所以我不确定我还能如何在我的模板中订购它。我的服务将一个数组传递给一个回调函数,该函数在 TS 主页的构造函数中触发。我为此悬赏了,因为有人提供的第一个解决方案对我不起作用..一直导致错误。

HOME.HTML

<ion-card id="card" *ngFor="let event of listOfEvents" >      

<ion-row id="row1">
<ion-col>
<span class="showDetails">Date:</span>
{{getFormattedTime(event.eventTime, 'MM-dd-yyyy')}}
</ion-col>
<ion-col>
<span class="showDetails">Time:</span>
{{getFormattedTime(event.eventTime, 'HH:MM')}}
</ion-col>
<ion-col>
<span class="showDetails">Venue:</span>
{{event.venue}}
</ion-col>
</ion-row>

</ion-card>

MyService.TS

getPosts (selectedCity, successCallback, failureCallback) {

OnymosUtil.getData(

'/events/' + selectedCity,
function getPostsSuccess (listOfEventsObject){
successCallback(listOfEventsObject);
},//close function getPostSuccess
function getPostsFailure (error) {
failureCallback(error);
},
{
orderByField: 'createdTime', //OrderByField not working
limitToFirst: 100
});

}//end getPosts

HOME.TS

export class Home {

listOfEvents: Array<any> = [];
postEvent: any;

constructor (public navCtrl: NavController,
public popoverCtrl: PopoverController,
public getPostSrvc: getPostsService) {

this.listOfEvents = [];
let that = this;

this.getPostSrvc.getPosts(
this.selectedCity,
function getPostsSuccess (listOfEventsObject) {
for (var i in listOfEventsObject) {
that.listOfEvents.push(listOfEventsObject[i]);
}
},
function getPostsFailure (error) {
console.log('ERROR : home.ts : Failed retrieving Posts - ' + error);
});
}//close constructor
}//close class

最佳答案

只需在客户端对其进行排序

function successCallback (listOfEventsObject) {

for (var x in listOfEventsObject) {
that.listOfEvents.push(listOfEventsObject[x]);
}
// sort
that.listOfEvents = that.listOfEvents.sort(function(a, b) {
return a.createdTime - b.createdTime;
// or vice versa
// or any other way you wish to sort
});

}

关于javascript - 我如何按最近创建的列表列出提要中的帖子?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44376962/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com