草庐IT

Flutter multiple where case 不起作用

coder 2023-07-23 原文

是否可以根据多个文档 ID 获取值?

CollectionReference col1 =  Firestore.instance
        .collection('service');
     col1.where("title", isEqualTo:"Ac replaciment")
    .where("title",isEqualTo:"Oil Service")
        .getDocuments()

这段代码没有给出任何结果

 CollectionReference col1 =  Firestore.instance
            .collection('service');
         col1.where("title", isEqualTo:"Ac replaciment")

            .getDocuments()

这个代码我得到了结果
但是我的标题是“Ac replaciment”和“Oil Service”但是当我更严格地调用时它没有给出结果
我需要查询 where title =="Oil Service"or title =="Ac replaciment" 如何在带有 flutter 的 firestore 中执行此操作



当我运行此代码时,它会从服务器返回所有数据

CollectionReference col1 = Firestore.instance.collection('service');

    col1.where("title", isEqualTo: "Ac replaciment");

    col1.getDocuments().

但如果 title=="Ac replaciment" 我只需要得到结果 为什么会发生这个问题?正确的代码是什么?

最佳答案

我可以想到两种解决方案。

<强>1。推送两个单独的查询调用并连接结果。

当您向服务器发送两个单独的查询时,这可能会导致更长的数据检索时间。

CollectionReference col1 = Firestore.instance.collection('service');
final acReplacimentList = await col1.where("title", isEqualTo: "Ac replaciment").getDocuments();
final oilServiceList = await col1.where("title", isEqualTo: "Oil Service").getDocuments();
return acReplacimentList.documents.addAll(oilServiceList.documents);

<强>2。在本地过滤文档。

这可能是一个更快的解决方案,但它会暴露所有其他不必要的文档。

CollectionReference col1 = Firestore.instance.collection('service');
final allList = await col1.getDocuments();
return allList.documents.where((doc) => doc["title"] == "Ac replaciment" || doc["title"] == "Oil Service");

已更新

<强>3。使用查询快照

CollectionReference col1 = Firestore.instance.collection('service');
final snapshots = col1.snapshots().map((snapshot) => snapshot.documents.where((doc) => doc["title"] == "Ac replaciment" || doc["title"] == "Oil Service"));
return (await snapshots.first).toList();

关于Flutter multiple where case 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56207070/

有关Flutter multiple where case 不起作用的更多相关文章

  1. ruby-on-rails - 如果 Object::try 被发送到一个 nil 对象,为什么它会起作用? - 2

    如果您尝试在Ruby中的nil对象上调用方法,则会出现NoMethodError异常并显示消息:"undefinedmethod‘...’fornil:NilClass"然而,有一个tryRails中的方法,如果它被发送到一个nil对象,它只返回nil:require'rubygems'require'active_support/all'nil.try(:nonexisting_method)#noNoMethodErrorexceptionanymore那么try如何在内部工作以防止该异常? 最佳答案 像Ruby中的所有其他对象

  2. ruby-on-rails - "assigns"在 Ruby on Rails 中有什么作用? - 2

    我目前正在尝试学习RubyonRails和测试框架RSpec。assigns在此RSpec测试中做什么?describe"GETindex"doit"assignsallmymodelas@mymodel"domymodel=Factory(:mymodel)get:indexassigns(:mymodels).shouldeq([mymodel])endend 最佳答案 assigns只是检查您在Controller中设置的实例变量的值。这里检查@mymodels。 关于ruby-o

  3. ruby - 字符串文字前面的 * 在 ruby​​ 中有什么作用? - 2

    这段代码似乎创建了一个范围从a到z的数组,但我不明白*的作用。有人可以解释一下吗?[*"a".."z"] 最佳答案 它叫做splatoperator.SplattinganLvalueAmaximumofonelvaluemaybesplattedinwhichcaseitisassignedanArrayconsistingoftheremainingrvaluesthatlackcorrespondinglvalues.Iftherightmostlvalueissplattedthenitconsumesallrvaluesw

  4. ruby - 为什么这个 eval 在 Ruby 中不起作用 - 2

    你能解释一下吗?我想评估来自两个不同来源的值和计算。一个消息来源为我提供了以下信息(以编程方式):'a=2'第二个来源给了我这个表达式来评估:'a+3'这个有效:a=2eval'a+3'这也有效:eval'a=2;a+3'但我真正需要的是这个,但它不起作用:eval'a=2'eval'a+3'我想了解其中的区别,以及如何使最后一个选项起作用。感谢您的帮助。 最佳答案 您可以创建一个Binding,并将相同的绑定(bind)与每个eval相关联调用:1.9.3p194:008>b=binding=>#1.9.3p194:009>eva

  5. ruby-on-rails - Spring 不起作用。 [未初始化常量 Spring::SID::DL] - 2

    我无法运行Spring。这是错误日志。myid-no-MacBook-Pro:myid$spring/Users/myid/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/spring-0.0.10/lib/spring/sid.rb:17:in`fiddle_func':uninitializedconstantSpring::SID::DL(NameError)from/Users/myid/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/spring-0.0.10/li

  6. ruby-on-rails - Simple_form 必填字段不起作用 - Ruby on Rails - 2

    我在RoR应用程序中有一个提交表单,是使用simple_form构建的。当字段为空白时,应用程序仍会继续下一步,而不会提示错误或警告。默认情况下,这些字段应该是required:true;但即使手动编写也行不通。该应用有3个步骤:NewPost(新View)->Preview(创建View)->Post。我的Controller和View的摘录会更清楚:defnew@post=Post.newenddefcreate@post=Post.new(params.require(:post).permit(:title,:category_id))ifparams[:previewButt

  7. ruby-on-rails - Heroku Action 缓存似乎不起作用 - 2

    我一直在Heroku上尝试不同的缓存策略,并添加了他们的memcached附加组件,目的是为我的应用程序添加Action缓存。但是,当我在我当前的应用程序上查看Rails.cache.stats时(安装了memcached并使用dalligem),在执行应该缓存的操作后,我得到current和total_items为0。在Controller的顶部,我想缓存我有的Action:caches_action:show此外,我修改了我的环境配置(对于在Heroku上运行的配置)config.cache_store=:dalli_store我是否可以查看其他一些统计数据,看看它是否有效或我做错

  8. ruby-on-rails - Rake 预览在 Octopress 中不起作用 - 2

    我在我的机器上安装了ruby​​版本1.9.3,并且正在为我的个人网站开发一个octopress项目。我为我的gems使用了rvm,并遵循了octopress.org记录的所有步骤。但是我在我的rake服务器中发现了一些错误。这是我的命令日志。Tin-Aung-Linn:octopresstal$ruby--versionruby1.9.3p448(2013-06-27revision41675)[x86_64-darwin12.4.0]Tin-Aung-Linn:octopresstal$rakegenerate##GeneratingSitewithJekyllidenticals

  9. ruby - 比较运算符不起作用(在 erb View 中) - 2

    我是RubyonRails的新手,我正在尝试编写一个morethan表达式:5%>大于号不断抛出异常捕获错误。我不确定如何解决这个问题?编辑:这不是rails,也不是View,它是一个Ruby构造 最佳答案 使用5%>错误来自photo_limit而不是从Integer延伸类(猜测它真的是一个字符串),因此没有混合比较方法/s有关更多信息,请参阅:http://www.skorks.com/2009/09/ruby-equality-and-object-comparison/特别是你必须混入Comparable并定义方法。虽然在这

  10. Ruby 全局作用域 - 2

    在回答另一个问题时,我意识到下面的程序并没有完全按照我的想法去做。puts"test"self.puts"test"#=>privatemethod`puts'calledformain:Object(NoMethodError)异常让我感到惊讶,因为我一直认为顶级方法调用将由main对象实例解决,但事实似乎并非如此。谁是第一个电话的实际接收者?如何解决?这是仅适用于顶级范围内的方法调用的特殊规则吗? 最佳答案 这是一个gooddiscussion说的就是这个问题。顶级方法,由Kernel提供,自动包含在Object类中。这意味着内

随机推荐