angular - 升序行中的角度排序数据
问题描述
我尝试根据数据集的时间戳对数据进行排序。为此,我创建了此服务:
import { Injectable } from '@angular/core';
import {AngularFirestore} from 'angularfire2/firestore';
@Injectable({
providedIn: 'root'
}) export class BlogService {
constructor(private afs: AngularFirestore) { }
getStudents() {
return this.afs.collection('Blogs', ref => ref.orderBy('ts')).valueChanges();
}
}
目前我按升序接收数据,但我想按降序接收数据,这意味着最新的值在前。
解决方案
这可以按预期工作,
import {orderBy} from "lodash";
getStudents(){
return this.afs.collection('Blogs', ref => orderBy(ref, ['ts'], ['desc'])).valueChanges();
}
推荐阅读
- javascript - 如果选中其他单选按钮,请检查单选按钮
- html - 类型号不适用于小数位
- css - 在我的情况下,我必须为一行使用 5 col-md,另一个 col-md 需要在没有打开行的情况下进入下一行
- python - 如何将 dict keyx:valuex 列表转换为 dict key:keyx, value:valuex 列表?
- vue-material - 未在 Vue Material md-tabs 中列出的页面会抛出“未捕获的类型错误:无法读取属性 'parentNode' of null”
- matplotlib - 我可以反转matplotlib的pcolormesh的过程吗?
- mysql - MYSQL JOIN 3 tables where field in third tables must be 0 and nothing else
- mysql - Heroku deployment hangs on executing DB queries, then fails with Timed out running buildpack Node.js
- regex - 正则表达式获取列
- javascript - Use Recursion to Create a CountdownPassed (JS Algorithm)