[英]Flutter Firestore, sorting data by date
This is my search code.这是我的搜索代码。 I am using this code for get Card from firestore.
我正在使用此代码从 firestore 获取卡片。 I am trying to set sorting by date my cards.
我正在尝试设置按日期排序我的卡片。
How can I do that.我怎样才能做到这一点。 Thanks for help.
感谢帮助。
class SearchService {
List<Future<QuerySnapshot>> searchByName() {
return [
Firestore.instance
.collection('dis')
.where('no')
.getDocuments(),
];
}
}
A "where" clause isn't going to sort the query results for you. “where”子句不会为您排序查询结果。 You will need to use orderBy for that.
为此,您需要使用orderBy 。 You will also need to know the name of the date field to use for ordering, as shown in the documentation .
您还需要知道用于排序的日期字段的名称,如文档中所示。
Firestore.instance
.collection('dis')
.orderBy('date')
.getDocuments(),
If you don't have a field that stores a date for each document, you won't be able to order the results.如果您没有为每个文档存储日期的字段,您将无法对结果进行排序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.