Javascript 解析-未捕获类型错误:无法读取属性';获取';未定义的
我正在使用javascript解析。我试图得到一个对象,我正在密切关注文档。我最终还是犯了错误 未捕获的TypeError:无法读取未定义的属性“get”Javascript 解析-未捕获类型错误:无法读取属性';获取';未定义的,javascript,jquery,function,parse-platform,Javascript,Jquery,Function,Parse Platform,我正在使用javascript解析。我试图得到一个对象,我正在密切关注文档。我最终还是犯了错误 未捕获的TypeError:无法读取未定义的属性“get” $(document).ready(function(){ Parse.initialize("myInfo","myInfo"); var count = Parse.Object.extend('overallCount'); var myQuery = Parse.Query(count); myQuery.get('Gqwk38
$(document).ready(function(){
Parse.initialize("myInfo","myInfo");
var count = Parse.Object.extend('overallCount');
var myQuery = Parse.Query(count);
myQuery.get('Gqwk38uUYz', { //HERE IS THE PROBLEM
success: function(count) {
// The object was retrieved successfully.
var myCount = count.get('count');
var updatedCount = myCount+1;
$("#myNum").val(updatedCount);
count.save(null, {
success: function(count) {
count.set('count', updatedCount);
count.save();
},
error: function(model, error) {
// This will be called.
// error is an instance of Parse.Error with details about the error.
if (error.code === Parse.Error.OBJECT_NOT_FOUND) {
alert("Uh oh, we couldn't find the object!");
} else if (error.code === Parse.Error.CONNECTION_FAILED) {
alert("Uh oh, we couldn't even connect to the Parse Cloud!");
}
}
});
},
error: function(object, error) {
// The object was not retrieved successfully.
// error is a Parse.Error with an error code and message.
}
});
});
您将得到错误,因为myQuery确实未定义。您必须使用“新建”来创建查询对象。将类名大写也是一种很好的做法:
var Count = Parse.Object.extend('overallCount');
var myQuery = new Parse.Query(Count);