第一天使用 React Native 和 Realm,我很难弄清楚如何通过两个 Realm 列表对象执行查询。
Tasks
have Reservations
, 其中有Renters
, 其中有first_name
and last_name
字段。我希望我的用户能够通过承租人的名字和姓氏搜索任务。
本质上,“给我承租人名字或姓氏以“xyz”开头的所有任务”
const TaskSchema = {
name:'Task',
properties: {
reservations:{ type: LIST, objectType: ReservationSchema.name },
}
},
const ReservationSchema = {
name:'Reservation',
properties: {
renters:{ type: LIST, objectType: RenterSchema.name },
},
}
const RenterSchema = {
name:'Renter',
properties: {
first_name:{ type:STRING, optional:true },
last_name:{ type:STRING, optional:true },
},
}
我只是不知道如何设置查询和谓词来完成此任务。
您可以过滤嵌套对象。
let tasks = realm.objects('Dog');
let xyzTasks = task.filtered('reservations.renters.first_name BEGINSWITH "xyz" OR reservations.renters.last_name BEGINSWITH "xyz"');
参考:https://realm.io/docs/react-native/latest/#filtering https://realm.io/docs/react-native/latest/#filtering
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)