简体   繁体   English

解析云代码 - 在“正常”功能中查询用户问题

[英]Parse cloud code - query user issue in "normal" function

I cannot get cloud code to query a user when using a "standard" function...使用“标准”功能时,我无法获取云代码来查询用户...

If I define the function (as below), it works fine...如果我定义函数(如下),它工作正常......

Parse.Cloud.define("findUser1", function(request, response){
   Parse.Cloud.useMasterKey();
   var query = new Parse.Query(Parse.User);
   query.equalTo("objectId", "2FSYI1hoJ8"); // "2FSYI1hoJ8" is the objectId of the User I am looking for
   query.first({
       success: function(user){
       response.success(user);
   },
   error: function(error) {
       console.error(error);
       response.error("An error occured while lookup the users objectid");
   }
   });
 });

In this version, the function will be called, but the query within will not...在这个版本中,该函数将被调用,但其中的查询不会...

function findThisUser(theObject){
    console.log("findThisUser has fired... " + theObject); //confirms "theObject" has been passed in
    Parse.Cloud.useMasterKey();
    var query = new Parse.Query(Parse.User);
    query.equalTo("objectId", "2FSYI1hoJ8"); // "2FSYI1hoJ8" is the value of "theObject", just hard coded for testing
   query.first({
       success: function(users){
       console.log("the user is... " + users);
       // do needed functionality here
   },
       error: function(error) {
       console.error(error);
   }
   });
};

Cloud code does not allow global variables, and I do not see how to pass in a variable to a "defined" function from another one.云代码不允许全局变量,我不知道如何将变量从另一个变量传递给“已定义”函数。 This is crucial as an outside function must be called to run the required tasks on the returned user.这是至关重要的,因为必须调用外部函数才能在返回的用户上运行所需的任务。 (This happens elsewhere and has to happen AFTER everything else does. This is the confirmation, and is supposed to be used by other functions as well) All potential information found to date has not helped, and the only experience I have in server side javascript is what I have cobbled together from other cloud code... (这发生在其他地方,并且必须在其他所有事情之后发生。这是确认,并且应该被其他功能使用)迄今为止发现的所有潜在信息都没有帮助,而且我在服务器端 javascript 中的唯一经验是我从其他云代码拼凑出来的......

Any ideas on what I am missing?关于我所缺少的任何想法?

This link may help, i had similar issue yesterday and after moving the code a little, and having the response.success(user);这个链接可能会有所帮助,昨天我遇到了类似的问题,在稍微移动了代码并获得了 response.success(user); in my function all worked fine.在我的功能中一切正常。

Parse Cloud Code retrieving a user with objectId 使用 objectId 检索用户的解析云代码

Not your exact issue - but this may help.不是您的确切问题 - 但这可能会有所帮助。

Heres is the code i use now:这是我现在使用的代码:

Parse.Cloud.define("getUserById", function (request, response) {
//Example where an objectId is passed to a cloud function.
var id = request.params.objectId;

Parse.Cloud.useMasterKey();
var query = new Parse.Query(Parse.User);
query.equalTo("ObjectId", id);

query.first(
{
    success: function(res) {
        response.success(res);
    },
    error: function(err) {
        response.error(err);
    }
});

}); });

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM