Parse - Uncaught TypeError: Cannot read property 'get' of undefined

放肆的年华 提交于 2020-01-15 09:50:08

问题


I am using Parse with javascript. I am trying to get an object and I am following the documentation closely. I still end up with the error

Uncaught TypeError: Cannot read property 'get' of undefined

$(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.

    }
});
});

回答1:


You are getting the error because myQuery is indeed undefined. You have to use "new" to create a query object. It's also good practice to capitalize class names:

var Count = Parse.Object.extend('overallCount');
var myQuery = new Parse.Query(Count);


来源:https://stackoverflow.com/questions/26092517/parse-uncaught-typeerror-cannot-read-property-get-of-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!