Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/452.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在服务器端调用解析函数_Javascript_Parse Platform_Cloud_Server Side - Fatal编程技术网

Javascript 在服务器端调用解析函数

Javascript 在服务器端调用解析函数,javascript,parse-platform,cloud,server-side,Javascript,Parse Platform,Cloud,Server Side,我要的是解析器, 在服务器端(云代码),是否有方法调用其他函数中定义的函数?不应在客户端上调用函数 Parse.Cloud.define("getProfiles", function(request, response) {..}) Parse.Cloud.define("otherFunction', function(request){ //call to getProfiles }) 建议按如下方式调用定义的函数: 您可以使用Parse.Cloud.run Parse.Cloud.

我要的是解析器, 在服务器端(云代码),是否有方法调用其他函数中定义的函数?不应在客户端上调用函数

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

Parse.Cloud.define("otherFunction', function(request){

//call to getProfiles })
建议按如下方式调用定义的函数:

您可以使用
Parse.Cloud.run

Parse.Cloud.run("getProfiles ", {
    //here you can pass the function request parameters
    userId: user.id
}).then(function(result) {
    //here you will handle the returned results (if function returned response.success())
    console.log(result);
}, function(error) {
    //handle errors if called function returned response.error()
    console.error(error);
});

希望它有帮助

这可以通过开发策略解决。我一直习惯于使用
Parse.Cloud.define
作为包装函数进行外部调用的方法,总是按照如下方式构建和命名它们

// this is just a "wrapper" for the simple JS function
Parse.Cloud.define("getProfiles", function(request, response) {
    // the only thing I allow to happen here is:
    // 1) unwrap params...
    var param = request.params.param;
    // 2) call an unwrapped function by the same name (this assumes it returns a promise)
    getProfiles(param).then(function(result) {
        // invoke response success and error
        response.success(result);
    }, function(error) {
        response.error(error);
    });
});

// always have an unwrapped function named identically
function getProfiles(param) {
    // do some work and (usually) return a promise
}

云中的其他函数(包装或取消包装)现在可以直接调用取消包装函数。

通过cloud.run()在云中调用函数需要花费额外的精力来展开和取消包装参数,生成请求和响应,等等,以及使调用方更加详细。您将需要学习如何使用。这样您就不必像那样调用parse。.then方法将为您的代码创建一个顺序,并使您的代码在继续之前像通常一样等待其他代码完成。