首页 > 解决方案 > 在 Flutter 中,如何使用 .where 来检查字段是否在本地列表中?

问题描述

我正在尝试加载 QuerySnapshot 但过滤字段“f_ID”是否在本地列表中。如果是,请不要添加它。

但是使用 .where 我无法访问我的本地列表对象。有什么办法吗?

 List<Map> the_List = new List();
  // map elements format: {'f_ID': xxxx, 'date': xxxx}
  // date is irrelevant to this search
 QuerySnapshot querySnapshot = await Firestore.instance
          .collection('Queue')
          .orderBy('clo_Score')
          .limit(25)
          .where("f_ID" ??????)
          .getDocuments();

标签: flutterdart

解决方案


用于检索文档列表的 .where 查询用于过滤您可以检索的文档。

它允许您将参数与相等的、或多或少的条件和其他一些条件进行比较。

在此处阅读有关 Firestore 查询的更多信息https://firebase.google.com/docs/firestore/query-data/queries

如果你想检查一个 id 是否在你的 LOCAL 列表中已经检索到,你应该使用数据库查询的结果 => QuerySnapshot。

querySnapshot.data.documents.where((doc)=> doc['f_ID'] == null)


推荐阅读