繁体   English   中英

将多个参数传递给promise函数?

[英]Passing more than one argument in to a promise function?

通常,您需要将“另一个”参数以及“结果”传递给链式函数。 怎么做?

这是一个Parse云代码示例:

var _ = require('underscore');
Parse.Cloud.define("doSomething", function(request, response)
    {
    var companyId = request.params.company;
    blah...

    companyFromCompanyId(companyId).then(function(company)
        {
        blah...
        return employeesFromCompany(company, kount);

    }).then(function(employees)
        {
        blah...
        // here, we would like to have passed in 'company' as an argument
        // as well as the "employees" result:
        ...  company.get("name") ...
        blah...
        }
        ,
        function(error) {blah...}
        );
});

所以, then(function(employees)then(function(employees)我想加入“更多的论点”。

(显然,一个人可以在更大的范围内制作一个变量。在这个问题上,我想问如何将更多的参数传递给.then)

根据@BenjaminGruenbaum的评论进行更新

    Parse.Cloud.define("doSomething", function(request, response) {
        var companyId = request.params.company;
        blah...

        companyFromCompanyId(companyId)
          .then(function(company) {
             return [employeesFromCompany(company, kount), company];
           })
          .spread(function(employees, company)
            {
              blah... // employees
              var theCompanyName = company.get("name");
              blah...
            })
          .catch(function(error) {blah...});
    });

暂无
暂无

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

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