Question

I have a matchCenterItem object in my Parse cloud code with properties like categoryId, minPrice, etc. What I want to do is iterate through every instance of matchCenterItem that a user has, and then reference specific properties of it in the code. So something like this:

Parse.Cloud.define("MatchCenterTest", function(request, response) {

  var matchCenterItem = Parse.Object.extend("matchCenterItem");  
  for (let i of matchCenterItem) {
         console.log(i.categoryId);
         console.log(i.minPrice);
  }

  success: function (httpResponse) {

          console.log('It worked!');
          response.success('Yay!');

  },
          error: function (httpResponse) {
              console.log('error!!!');
              response.error('Request failed');
          }
});

This is obviously wrong, I'm just not sure how to form the syntax to accomplish this correctly.

Was it helpful?

Solution

You'll need to query the class to look at the contents:

Parse.Cloud.define("MatchCenterTest", function(request, response) {

  var query = new Parse.Query("MatchCenterTest");
  query.limit(10);
  query.find().then(function(results) {
    for (i=0; i<results.length; i++) {
     console.log(results[i].get('categoryId'));
     console.log(results[i].get('minPrice'));
    }
    response.success('Cool');
  }, function(error) {
    response.error('Uncool');
  });

});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top