[英]Parse.com — Cloud Code/JS — “Cannot call method 'set' of undefined”
So, my Javascript isn't the best but I have to venture into it to run some Cloud Code functions. 因此,我的Javascript并不是最好的,但是我必须冒险使用它来运行一些Cloud Code函数。 I have the following:
我有以下内容:
Parse.Cloud.define("setCommentIsTitle", function(request, response) {
Parse.Cloud.useMasterKey();
var query = new Parse.Query("Comment");
query.equalTo("objectId", request.params.objectId);
query.first({
success: function(object) {
object.set('isTitle', request.params.isTitle);
return object.save(); },
error: function(error) {
alert("Error: " + error.code + " " + error.message);
}
});
I logged the objectId
I'm passing in as request.params.objectId
and it's correct. 我记录了我作为
request.params.objectId
传入的objectId
,这是正确的。 What I don't get is that success
is being called, but then I'm getting the following Cloud Code log when I console.log
object: 我没有得到的是
success
被称为,但是当我console.log
对象时,我得到了以下云代码日志:
I2013-10-21T17:27:52.120Z] object = undefined
And the following error returned in XCode: 并且在XCode中返回以下错误:
code=141, error=TypeError: Cannot call method 'set' of undefined
If I'm calling the first
function on query
, and success
is being called, shouldn't that mean there is an object returned? 如果我在
query
上调用第first
函数,并且正在调用success
,那是否就意味着返回了一个对象? Why is object
undefined? 为什么
object
未定义?
OK, so this was a stupid error on my part, but also abetted by a confusing Parse error message. 好的,所以这对我来说是一个愚蠢的错误,但也因令人困惑的“解析”错误消息而得到了鼓励。
My class is called Comments
and not Comment
, so I was looking up the wrong class. 我的班级称为
Comments
而不是Comment
,所以我在查找错误的班级。 However, since success was called on the query I started looking in all the wrong places for the error. 但是,由于在查询中调用了成功,因此我开始在所有错误的位置查找错误。
Why would success be called if I'm querying a class that doesn't even exist?? 如果我查询一个甚至不存在的类,为什么会调用成功?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.