我的 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');
}
});
这显然是错误的,我只是不确定如何形成正确完成此操作的语法。
最佳答案
您需要查询类以查看内容:
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');
});
});
关于javascript - 在 for 循环中引用对象的特定属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24004729/