解析-未捕获的TypeError:无法读取未定义的属性"get" [英] Parse - Uncaught TypeError: Cannot read property 'get' of undefined

查看:536
本文介绍了解析-未捕获的TypeError:无法读取未定义的属性"get"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JavaScript解析.我正在尝试获取对象,并且正在密切关注文档.我仍然遇到错误

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

未捕获的TypeError:无法读取未定义的属性'get'

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.

    }
});
});

推荐答案

由于myQuery确实是未定义的,因此出现错误.您必须使用新建"来创建查询对象.最好使用大写的类名:

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);

这篇关于解析-未捕获的TypeError:无法读取未定义的属性"get"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆