我有json:
{
"title": "Title 2",
"body": "Body 2",
"status_info": {
"is_favorite": false,
"is_like": false,
"like_count": 0
},
"id": "47e7704e-89f1-4d0d-8da1-52a080d56f46"
}
两个领域对象:
open class Actuality : RealmObject() {
@PrimaryKey lateinit var id: String
@SerializedName("status_info")
lateinit var statusInfo: StatusInfo
...
}
open class StatusInfo : RealmObject() {
@SerializedName("is_like")
var isLiked: Boolean = false
@SerializedName("is_favorite")
var isFavorite: Boolean = false
@SerializedName("like_count")
var likeCount: Int = -1
}
我使用RealmAdapter RealmResults进行实时更新, 但是当我尝试用likeCount对现状进行排序时,我有问题。
我试过
data?.sort("likeCount", Sort.DESCENDING)
data?.sort("statusInfo.likeCount", Sort.DESCENDING)
但是领域让我异常,那个"字段名称' likeCount'不存在。" 我如何在RealmResults中处理realm嵌套对象?