[英]Angularfire2 - how to Reverse the observable list
I'm using this code to reverse the list: 我正在使用此代码来反转列表:
this.items = this.db.list('/privacy').map( (array) => {return array.reverse()} ) as FirebaseListObservable<any[]>;
and l called the list in this way: 我以这种方式调用列表:
<ion-item *ngFor="let item of items | async"> {{item.order}}</ion-item>
and this work for me (the array was reversed). 并为我工作(阵列被颠倒了)。 but my problem not here, my problem is when a new data pushed to the list the order of the list messed up!.
但是我的问题不在这里,我的问题是当新数据推送到列表时,列表的顺序变得混乱! After refreshing the page the order reverse again.
刷新页面后,顺序再次相反。
this is a chat application not professional way to reload the page or restart the app.
这是一种聊天应用程序,不是重新加载页面或重新启动应用程序的专业方法。
Try this: 尝试这个:
this.db.list('/privacy',{
query: {
orderByChild: 'createDate' //replace with the field you want to order by
}
})
.subscribe((items: any[]) =>{
return items.reverse();
})
This works when working with an observable array 这在使用可观察数组时有效
<div *ngFor="let item of (items | async).?reverse()">
Not sure if this applies to AngularFireLists 不知道这是否适用于AngularFireLists
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.