parse.com如何使用查询限制查询每个?

时间:2015-03-11 18:25:36

标签: javascript parse-platform

我需要订购并限制我的查询,然后我需要迭代结果但是不可能。

Cannot iterate on a query with sort, skip, or limit.

我该怎么做?

这是我的查询,我想发布帖子,标签为user,限制为100张帖子:

var query = new Parse.Query('post');
    query.equalTo('publish', true);
    query.descending('createdAt');
    query.containedIn('tags', request.user.get('tags'));
    query.limit(100);
    query.each(function(post) {

        var postJSON = JSON.parse(JSON.stringify(post));
        var promises = [];

        var promise1 = getPseudo(post.get('author').id).then(function(user) {
                postJSON.pseudo = user.get('pseudo');
            }, function(error) {});

        var promise2 = isCertified(post.get('author').id).then(function(result) {
                postJSON.isCertified = !!result;
            }, function(error) {});

        promises.push(promise1, promise2);
        promisesAll.push(promise1, promise2);

        Parse.Promise.when(promises)
            .then(function() {
                posts.push(postJSON);
            }, function(error) {});

    }, {
        success: function() {
            Parse.Promise.when(promisesAll)
                .then(function() {
                    response.success(postsOrdered);
                });
        }
    });

1 个答案:

答案 0 :(得分:0)

您需要加载下划线,如下所示: var _ = require('underscore');

之后你可以像这样循环每个结果:

var query = new Parse.Query('post');
    query.equalTo('publish', true);
    query.descending('createdAt');
    query.containedIn('tags', request.user.get('tags'));
    query.limit(100);
    query.find({
        success: function(posts) {

            _.each(function(post) {
                // What you want
            }

        }
    });