gpt4 book ai didi

javascript - 结果 : TypeError: Object [object Object] has no method 'set' when trying to edit Parse object

转载 作者:行者123 更新时间:2023-12-03 11:30:47 25 4
gpt4 key购买 nike

当我尝试运行以下后台作业时,出现错误,指出 Result: TypeError: Object [object Object] has no method 'set',指的是我尝试设置的行对象的“Number”属性返回值 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');
}

});

});

最佳答案

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]

关于javascript - 结果 : TypeError: Object [object Object] has no method 'set' when trying to edit Parse object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26742955/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com