在firebase和Ionic 2上降序orderByChild() [英] Descending orderByChild() on firebase and Ionic 2
本文介绍了在firebase和Ionic 2上降序orderByChild()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要按日期排序项目,但显然我需要降序排序以正确的顺序显示帖子...
I need get items sorted by date, but obviously I need descending sorted to show the posts in correct order...
import {
AngularFireDatabase
} from 'angularfire2/database';
import 'rxjs/add/operator/map';
/*
Generated class for the FirebaseProvider provider.
See https://angular.io/docs/ts/latest/guide/dependency-injection.html
for more info on providers and Angular 2 DI.
*/
@Injectable()
export class FirebaseProvider {
constructor(public afd: AngularFireDatabase) {}
getPostsItems() {
return this.afd.list('/Posts/', {
query: {
orderByChild: "date",
}
});
}
此查询返回一个上升顺序,我需要一个后代顺序它在Firebase网站中没有解释。
This query returns a ascendent order and I need a descendent order that it's not explained in Firebase web.
我需要哪些查询?
推荐答案
一种方法可能是颠倒组件模板中的顺序。首先,您会直接在您的组件中获得帖子列表:
One approach could be reversing the order in your component's template. First, you get a list of posts directly in your component:
posts.component.ts
export class PostsComponent {
posts: FirebaseListObservable<any>;
constructor(db: AngularFireDatabase) {
this.posts = db.list('/posts', {
query: {
orderByChild: 'date'
}
});
}
}
然后,您可以使用反转
在您的模板中撤消帖子订单的方法:
Then, you can use the reverse
method to reverse your posts' order in your template:
posts.component.html
<div *ngFor="let post of (posts | async)?.slice().reverse()">
<h1>{{ post.title }}</h1>
</div>
这篇关于在firebase和Ionic 2上降序orderByChild()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文