【问题标题】:Using Akita data store, how can I select all items where 2 properties match based on OR?使用秋田数据存储,如何选择所有基于 OR 的 2 个属性匹配的项目?
【发布时间】:2020-08-21 16:37:06
【问题描述】:

我想根据 2 个属性从秋田商店中选择值,其中任何一个都应该与我正在寻找的东西相匹配。

我从一个简单的开始(添加了 filterBy [] 知道我想过滤不止一件事):

this.myQuery.selectAll({
  filterBy: [
    (entity: MyEntityType) => entity.prop1 === thingToMatch 
  ]
}).subscribe((entities) => {})

正确返回匹配过滤器的实体对象。但是,实体上有 2 个属性,其中任何一个都可能具有我要匹配的值。于是我猜测了一下:

this.myQuery.selectAll({
  filterBy: [
    (entity: MyEntityType) => 
      entity.prop1 === thingToMatch || entity.prop2  === thingToMatch
  ]
}).subscribe((entities) => {})

那里的第二个代码块不返回实体,第一个返回匹配一个 ok。

我想我可以做一个 SelectAll 然后使用 TS 过滤,

this.myQuery.selectAll().subscribe((entities) => {  
   entities.filter(..... )
});

但我希望我可以在秋田选择框架内进行 OR。

在秋田商店选择上执行 OR 操作的正确语法是什么? 我什至应该使用 select() 吗?

【问题讨论】:

    标签: angular angular-akita akita


    【解决方案1】:

    我相信 Akita combineQueries 可以在这里工作。

    
    const filter1 = this.myQuery.selectAll({
      filterBy: [
        (entity: MyEntityType) => entity.prop1 === thingToMatch
      ]
    });
    
    const filter2 = this.myQuery.selectAll({
      filterBy: [
        (entity: MyEntityType) => entity.prop2  === thingToMatch
      ]
    });
    
    const result$ = combineQueries([filter1, filter2]).subscribe(...) 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-12
      • 1970-01-01
      • 2022-09-30
      • 1970-01-01
      • 2016-08-20
      • 2020-10-28
      相关资源
      最近更新 更多