我正在保存NSMutableArray
我试过这个:
var dataQuery:PFQuery = PFQuery(className: "Posts")
dataQuery.orderByDescending("likes") // but this doesn't make sense at all.
dataQuery.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
我希望帖子位于顶部,最大数量为likes
,依此类推。我怎样才能做到这一点?谢谢你的时间..
答案 0 :(得分:3)
这不是直接可行的。但是你可以添加一个likesCount属性,并在每次保存时通过云代码更新它。
Parse.Cloud.beforeSave("Posts", function(request, response)
{
var likes = request.object.has("likes") ? request.object.get("likes") : [];
request.object.set("likesCount", likes.length);
response.success();
});
然后使用likesCount
属性:
var dataQuery:PFQuery = PFQuery(className: "Posts")
dataQuery.orderByDescending("likesCount")
// ...