引用for循环中对象的特定属性

时间:2014-06-02 23:10:42

标签: javascript parse-platform

我的Parse云代码中有一个matchCenterItem对象,其属性类似于categoryId,minPrice等。我想要做的是遍历用户拥有的matchCenterItem的每个实例,然后引用代码中的特定属性。所以像这样:

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');
          }
});

这显然是错误的,我只是不确定如何形成语法来正确完成此操作。

1 个答案:

答案 0 :(得分:2)

您需要查询课程以查看内容:

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');
  });

});