使用React Native Realm来查询多个列表对象 [英] Use React Native Realm to Query through multiple List Objects

查看:376
本文介绍了使用React Native Realm来查询多个列表对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第一天使用React Native和Realm,我很难确定如何通过两个Realm List对象执行查询.

First day using React Native and Realm, and I'm having a hard time figuring how to perform a query through two Realm List Objects.

Tasks具有Reservations,具有Renters,具有first_namelast_name字段.我希望我的用户能够按承租人的名字和姓氏搜索任务.

Tasks have Reservations, which have Renters, which have first_name and last_name fields. I want my users to be able to search for tasks by the Renter's first and last names.

从本质上讲,将承租人的名字或姓氏以"xyz"开头的所有任务给我"

Essentially, "Give me all the tasks whose renter's first or last name begins with "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 },
  },
}

我只是不知道如何设置查询和谓词来完成此操作.

I just can't figure out how to set up my query and predicates to accomplish this.

推荐答案

您可以过滤嵌套对象.

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

这篇关于使用React Native Realm来查询多个列表对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆