我有一组视频对象,我试图从Parse中获取。每个视频都有一个名为mostRecentComments的属性,该属性是一个包含Comment对象指针的数组,包含注释主体和创建者。在客户端上,我尝试以显示“comment.creator.username
comment.body
”的方式显示这些评论。我正在尝试弄清楚如何将创建者包含在从我的Cloud Code返回的每个视频的最新评论数组中,试图避免运行类似的内容:
var promise = Parse.Promise.as();
_.map(video.get("mostRecentComments"), function (comment) {
promise = promise.then(function () {
return comment.fetch();
}).then(function (fetchedComment) {
return fetchedComment
});
return promise;
});
因为超时的风险。
上下文:
videoQuery.include("place");
videoQuery.include("creator");
videoQuery.include("mostRecentComments");
videoQuery.descending("createdAt");
videoQuery.equalTo("isAvailable", true);
videoQuery.limit(30);
if (page > 0) {
videoQuery.skip(30 * page);
}
likesQuery = user.relation("likes").query();
likesQuery.matchesKeyInQuery("objectId", "objectId", videoQuery);
Parse.Promise.when([likesQuery.find(), videoQuery.find()]).then(function (likes, videos) {
var results = [];
if (videos.length == 0) {
response.error("Could not find video results");
return;
}
_.each(videos, function (video) {
result = {
video: video,
isLiked: false
};
_.each(likes, function (like) {
if (like.id == video.id)
result.isLiked = true;
});
results.push(result);
});
var next_page = (videos.length == 30) ? page + 1 : -1;
response.success({
results: results,
next_page: next_page,
previous_page: page
});