I'm using Parse Cloud Code to host a web application but I'm having a problem trying to get a relation query to work. I've tried an example from Coderwall http://ift.tt/1B6sJXN but I'm not sure how to gather the result of the query before trying to render the result.
function queryProducts(limit) {
var post = Parse.Object.extend("Post");
var query = new Parse.Query(post);
query.limit(limit);
var data = new Array();
query.find().then(function (posts) {
var cb = _.after(posts.length, function () {
console.log("after"+ data);
return data;
});
_.each(posts, function (post) {
var images = post.relation("images");
images.query().find().then(function (images) {
data.push(post);
cb();
});
});
});
}
app.get('/', function (req, res) {
results = queryProducts(10);
res.render('index', { products: results });
});
Aucun commentaire:
Enregistrer un commentaire