*简单*解析云代码查询失败“TypeError:无法调用未定义的方法'get'\n检索该信息" [英] *Simple* Parse Cloud Code query failure "TypeError: Cannot call method 'get' of undefined\n retrieve that info "

查看:36
本文介绍了*简单*解析云代码查询失败“TypeError:无法调用未定义的方法'get'\n检索该信息"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几个小时以来,我一直在尝试做一些非常简单的事情,但我不知道自己做错了什么.我很简单地尝试通过 Cloud Code 从我的 Parse 数据集中查询第一个人的用户名,然后我想把它放到我的 iOS 应用程序中.尽管进行了所有尝试,但它似乎并没有奏效.你会在下面找到我的代码.

I've been trying to do something very simple for several hours now and I don't know what I'm doing wrong. I'm simple trying to query the username of the first person from my Parse data set via Cloud Code, and then I want to bring that down to my iOS application. Despite all attempts it doesn't seem to be working. Below you'll find my code.

Parse.Cloud.define("userName", function(request,response){

    var query = new Parse.Query(Parse.User);
    query.equalTo("username", request.params.username)
    query.first({
        success: function(getUserName) {
            var userString = getUserName.get("username");
            response.success(userString);
        },
        error: function(error) {
            alert("Error: " + error.code + " " + error.message);
        }
        });
    });





[PFCloud callFunctionInBackground:@"userName" withParameters:@{} block:^(NSString *result, NSError *error) {
        if (!error){
            NSLog(result);
        }
    }];

我也不应该说我不确定在参数部分除了用户名:"之外应该放什么

I should also not that I'm bot sure what to put in the Parameters section besides "username :"

此外,当我尝试部署 Parse Cloud 代码时,我收到类型错误:无法调用未定义的方法 'get'\n"

Further, when I try to deploy the Parse Cloud Code I get "TypeError: Cannot call method 'get' of undefined\n"

推荐答案

想通了.我的错误来自于对 Javascript 的理解不足.

Figured it out. My mistakes came from a poor understanding of Javascript.

下面的云代码得到了我想要的.

The below cloud code got what I wanted.

Parse.Cloud.define("userName", function(request,response){
var query = new Parse.Query(Parse.User);
query.equalTo("username", request.params.username);
query.first({
    success: function(object) {
        var userString = request.params.username;
        response.success(userString);
    },
    error: function(error) {
        alert("Error: " + error.code + " " + error.message);
    }
    });
});

我犯的错误是我试图在无法访问所述方法的对象上使用.get"方法.奇怪的是我试图用 request.object.get("username") 做同样的事情,但显然请求对象也无法访问 .get 方法(令人困惑,因为 Parse文档似乎表明它在其示例中确实如此).因此,结合下面rickerbh 的objective-c 代码执行上述操作,得到了我想要的结果.

The mistake I was making was that I was trying to use the ".get" method on an object that didn't have access to the said method. The weird thing is I tried to do the same thing with request.object.get("username") but apparently the request object also doesn't have access to the .get method (confusing because the Parse documentation seems to indicate that it does in its examples). So doing the above in combination with rickerbh's objective-c code below got me the result I was looking for.

如果有人可以在此处发布与 Parse 的云代码相关的 .get 方法的性质,这将有所帮助.干杯.

It would help if someone could post the nature of the .get method in relation to Parse's cloud code here. Cheers.

这篇关于*简单*解析云代码查询失败“TypeError:无法调用未定义的方法'get'\n检索该信息"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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