当我尝试运行以下后台作业时,我收到一条错误,指出Result: TypeError: Object [object Object] has no method 'set'
,指的是我尝试设置'数字'的行。要返回的值为2
的对象的属性。我之前使用过相同的格式来编辑Parse对象,它运行正常,我在这里做错了什么?
Parse.Cloud.job("sendLowPush", function(request, status) {
Parse.Cloud.useMasterKey();
/////////////
//send push notification to all users in the "lowPush" channel
//{Query the # value of pushIncrement with object id hKj2Eazz6h}
var pushIncrement = Parse.Object.extend("pushIncrement");
var pushIncrementQuery = new Parse.Query(pushIncrement);
pushIncrementQuery.equalTo('objectId', 'hKj2Eazz6h');
pushIncrementQuery.find({
success: function(results) {
for (var i = 0; i < results.length; ++i) {
var dayNumber = results[i].get("Number");
}
console.log('dem results be:' + dayNumber);
//Figure out whether its day 1, 2, or 3, and increment. Send lowPush if day 3.
if (dayNumber = 1){
//change it to 2
console.log('dayNumber is 1');
results.set('Number', '2');
results.save();
}
else if (dayNumber = 2){
//change it to 3
console.log('dayNumber is 2');
}
status.success("Push Notifications completed successfully.");
},
error: function(error) {
console.log('shit');
status.error('shitty shit');
}
});
});
答案 0 :(得分:1)
results
是对象列表。您无法在整个列表中设置Number
字段。但是,您似乎只查询具有特定ID的单个对象。在这种情况下,您应该使用.get
代替:
pushIncrementQuery.get('hKj2Eazz6h', {
success: function(obj) {
var dayNumber = obj.get("Number");
// ...
obj.set('Number', '2');
obj.save();
}
});
如果您想使用.find
,则必须访问列表中的正确元素,即results[i]
或results[0]
。