React native realmreact native:如何正确查询字符串数组

React native realmreact native:如何正确查询字符串数组,react-native,realm,React Native,Realm,有人能告诉我如何查询react native中realm为的字符串数组吗 假设我有一个如下所示的数组: const preferences = ["automatic","suv","blue",eco] const query = realm.objects("Cars").filtered('specifications = preferences[0] OR specifications = preferences[1]') 我想要的是得到领域结果,其中汽车属性“specificati

有人能告诉我如何查询react native中realm为的字符串数组吗

假设我有一个如下所示的数组:

const preferences = ["automatic","suv","blue",eco]
const query = realm.objects("Cars").filtered('specifications = preferences[0] OR specifications = preferences[1]')
我想要的是得到领域结果,其中汽车属性“specifications”中的所有字符串都在“preferences”中

例如:如果Cars.specification的实例包含[“automatic”,“suv”] 应该返回一个结果

但是,如果Cars.specification的实例包含[“automatic”、“suv”、“green”],则不应返回此实例

首选项的长度可能会有所不同

多谢各位

更新:

我尝试了以下几点:

const preferences = ["automatic","suv","blue",eco]
const query = realm.objects("Cars").filtered('specifications = preferences[0] OR specifications = preferences[1]')

正如您所看到的,OR运算符肯定是错误的,它是硬编码的。使用realm循环确实让我感到困惑。

测试单词是否在单词数组中的函数示例

function inArray(word, array) {
  var lgth = array.length;
  word = word.toLowerCase();
  for (var i = 0; i < lgth; i++) { 
    array[i] = (array[i]).toLowerCase();
    if (array[i] == word) return true;
  }

  return false;
}

const preferences = ["automatic","suv","blue","eco"];

const specifications = ["automatic","suv"] ;
const specifications2 = ["automatic","suv", "boat"] ;

function test(spec,pref){ 
  for (var i in spec){
    if(!inArray(spec[i],pref)){
      return false ;
    }    
  }
  return true;   
}

console.log(test(specifications,preferences));
console.log(test(specifications2,preferences));
函数数组(字、数组){
var lgth=array.length;
word=word.toLowerCase();
对于(var i=0;i

您尝试的代码是什么?这是一个简单的代码,您可以创建一个循环(例如)在你的车上。详细说明,并检查是否每件物品都在里面preferences@AlainIb感谢您的回复。我更新了我尝试的内容。但不幸的是,它是OR运算符,and运算符不起作用。但是查询是硬编码的,正如您所看到的,这不符合“首选项的长度可能不同”的要求“.与领域的循环确实让我困惑。我相信这是一个简单的代码,但我发疯了,无法解决它。我不使用realm,我发布了一个js解决方案,可能会有帮助。不幸的是,它不起作用。它必须是领域特定的解决方案。我刚刚读到realm不支持对列表属性的查询。只是通过一个变通办法