这些是您的许多选择中的一些:
在门1的后面,使用reduce来串行累加结果。
var models = [];[ function () { return ModelA.create(); }, function () { return ModelB.create(); }, function () { return ModelC.create(); }].reduce(function (ready, makeModel) { return ready.then(function () { return makeModel().then(function (model) { models.push(model); }); });}, Q()).catch(function (error) { // handle errors});在2号门的后面,将累积的模型打包成一个阵列,然后展开展开。
Q.try(function () { return ModelA.create()}).then(function(modelA){ return [modelA, ModelB.create()];}).spread(function(modelA, modelB){ return [modelA, modelB, ModelC.create()];}).spread(function(modelA, modelB, modelC){ // need to do stuff with modelA, modelB and modelC}).catch();在3号门后面,在父级范围中捕获结果:
var models [];ModelA.create().then(function(modelA){ models.push(modelA); return ModelB.create();}).then(function(modelB){ models.push(modelB); return ModelC.create();}).then(function(modelC){ models.push(modelC); // need to do stuff with models}).catch(function (error) { // handle error});


