【问题标题】:How to filter by item contained in a list in realm react native?如何按领域中列表中包含的项目进行过滤?
【发布时间】:2017-06-10 14:45:46
【问题描述】:

我正在执行以下查询:

realm.objects('Maker').filtered("categories CONTAINS $0", categoryObject)

但是我收到了这个错误:

Only 'equal' and 'not equal' operators are supported for object comparison

这是我的架构:

{ 
name: 'MakerOption',
primaryKey: 'serverId',
properties: {
  serverId: 'int',
  name: 'string',
  categories: {type: 'list', objectType: 'Category'},
}

{
name: 'Category',
primaryKey: 'serverId',
properties: {
  serverId: 'int',
  name: 'string'
}

关于这个主题的文档非常稀少。有没有其他方法可以做到这一点?

【问题讨论】:

    标签: react-native realm


    【解决方案1】:

    可以通过在查询中指定键路径来按链接或子对象的属性进行过滤,例如car.color == 'blue'

    所以您正在寻找以下查询:

    realm.objects('Maker').filtered("categories.serverId == $0", categoryObject.serverId)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-23
      • 1970-01-01
      • 1970-01-01
      • 2019-11-28
      • 2021-01-08
      • 1970-01-01
      • 2014-06-04
      相关资源
      最近更新 更多