过滤字符串列表属性
const BookrackSchema = {
name: 'Bookrack',
properties: {
book_names:'string[]',
}
};
Bookrack1.book_names=['A','B','C'];
Bookrack2.book_names=['B','C','D'];
Bookrack3.book_names=['C','D','E'];
a:realm.objects('Bookrack').filtered(`ANY book_names = $0 `,'B');
b:realm.objects('Bookrack').filtered(`book_names CONTAINS $0 `,'B');
获得Bookrack1和Bookrack2
aResult:The keypath following 'ANY' or 'SOME' must contain a list
bResult:Object type 'Table' not supported
答案 0 :(得分:0)
目前,Realm JS仅支持查询对象列表,但我们计划添加对查询基本类型列表的支持。在那之前,你可以使用类似的东西:
const Realm = require('realm');
const BookrackSchema = {
name: 'Bookrack',
properties: {
book_names:'string[]',
}
};
let realm = new Realm({schema: [BookrackSchema]});
realm.write(() => {
realm.create('Bookrack', { book_names: ['A','B','C']});
realm.create('Bookrack', { book_names: ['B','C','D']});
realm.create('Bookrack', { book_names: ['C','D','E']});
});
let objs = realm.objects('Bookrack');
let Bs = objs.filter(obj => { return obj.book_names.reduce((acc, cur) => { return acc || cur === 'B' }, false)});