【问题标题】:how to convert RealmList<T> to RealmResults<T>如何将 RealmList<T> 转换为 RealmResults<T>
【发布时间】:2019-06-13 17:31:55
【问题描述】:

我正在研究领域数据库,并希望将 RealmList 转换为 RealmResults。 realmlist 是领域对象的属性。

【问题讨论】:

    标签: java android realm


    【解决方案1】:

    简单使用查询列表:

    class MyObject extends RealmObject {
    
        RealmList<MySubObject> subObjects;
    }
    
    ...
    
    myObject.subObjects.where().findAll(); //returns a RealmResults
    
    //you can query your list like
    myObject.subObjects
         .where()
         .equalTo("status", "done")
         .findAll(); //you can use sort, findFirst etc
    

    【讨论】:

      【解决方案2】:

      很简单:

      RealmResults<T> results = realmList.where().findAll();
      

      请注意,这只适用于托管 RealmList。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-07-18
        • 2017-09-01
        • 1970-01-01
        • 2014-02-05
        • 2016-02-29
        • 2010-11-18
        • 2012-01-22
        • 1970-01-01
        相关资源
        最近更新 更多