通常,您需要将“另一个”参数传递给链式函数以及“结果”。怎么做?
这是一个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)
答案 0 :(得分:1)
根据@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...});
});