简体   繁体   English

*简单*解析云代码查询失败“ TypeError:无法调用未定义的方法'get'\\ n检索该信息”

[英]*Simple* Parse Cloud Code query failure “TypeError: Cannot call method 'get' of undefined\n retrieve that info ”

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. 我很简单地尝试通过Cloud Code从我的Parse数据集中查询第一人称的用户名,然后将其带到我的iOS应用程序中。 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 :" 我也不应该确定除了“ username:”之外,还要在Parameters部分中放置什么内容。

EDIT: Further, when I try to deploy the Parse Cloud Code I get "TypeError: Cannot call method 'get' of undefined\\n" 编辑:此外,当我尝试部署解析云代码时,我得到“ TypeError:无法调用未定义的方法'get'\\ n”

Looking at your cloud code, you're expecting a request.params.username to contain a value that you can use to lookup in the User class, via the username column. 看你的云代码,你期待一个request.params.username包含,您可以使用在查找一个值User类,通过username列。 I typically access attributes of the params object via a key (I'm not sure if this is required, I just know it works for me). 我通常通过一个键访问params对象的属性(我不确定是否需要这样做,我只是知道它对我有用)。 Try changing 尝试改变

query.equalTo("username", request.params.username)

to

query.equalTo("username", request.params["username"]);

Then, you need to get that data into the cloud function. 然后,您需要将该数据放入云功能。 Your Objective-C code passes an empty parameter block in, so looking anything up there will result in a whole lot of nothing. 您的Objective-C代码会传入一个空的参数块,因此在该处查找任何内容将不会有任何结果。 Change your PFCloud call to 将您的PFCloud呼叫更改为

[PFCloud callFunctionInBackground:@"userName" withParameters:@{@"username": @"theusernameyouwanttolookup"} block:^(NSString *result, NSError *error) {

And hopefully you'll have some better luck. 希望您会遇到好运。

Figured it out. 弄清楚了。 My mistakes came from a poor understanding of Javascript. 我的错误来自对Java语言的理解不足。

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

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. 我犯的错误是我试图在无法访问所述方法的对象上使用“ .get”方法。 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). 奇怪的是我尝试对request.object.get("username")做同样的事情,但是显然请求对象也没有访问.get方法的权限(令人困惑,因为Parse文档似乎表明它确实可以在其示例中)。 So doing the above in combination with rickerbh's objective-c code below got me the result I was looking for. 因此,将以上内容与下面的rickerbh的Objective-C代码结合使用,可以得到我想要的结果。

It would help if someone could post the nature of the .get method in relation to Parse's cloud code here. 如果有人可以在此处发布与Parse的云代码相关的.get方法的性质,那将有所帮助。 Cheers. 干杯。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Parse.com Cloud Code错误:TypeError:无法调用未定义的方法'get' - Parse.com Cloud Code error : TypeError: Cannot call method 'get' of undefined 解析失败:TypeError:无法调用未定义的方法'get' - Parse Failed with: TypeError: Cannot call method 'get' of undefined 解析查询“无法调用未定义的方法'equalTo'” - Parse Query “Cannot call method 'equalTo' of undefined” TypeError:无法调用未定义的方法“ get” - TypeError: Cannot call method 'get' of undefined '失败:TypeError:运行解析查询时无法调用方法'replace'of undefined' - 'Failed with: TypeError: Cannot call method 'replace' of undefined' when running Parse query Parse.com背景作业云代码无法调用未定义的方法'then' - Parse.com Background Job cloud code cannot call method 'then' of undefined Parse.com —云代码/ JS —“无法调用未定义的方法'set'” - Parse.com — Cloud Code/JS — “Cannot call method 'set' of undefined” TypeError:无法在Object.Parse.File.save调用未定义的方法'then' - TypeError: Cannot call method 'then' of undefined at Object.Parse.File.save 解析云代码:在关系上调用.query()时,“无法调用null的方法'_toPointer' - Parse Cloud Code: “Cannot call method '_toPointer' of null” when calling .query() on a relation TypeError:无法调用未定义的方法“ $ on” - TypeError: Cannot call method '$on' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM