如何通过 Bluebirds .map 携带一些数据?

How do I carry some data through Bluebirds .map?

我正在使用 Blubird 和 Sequelize(在幕后使用 Blubird)。

假设我的代码类似于:

Feed.findAll()
    .map(function (feed) { //  <---- this is what I'm interested in below
        // do some stuff here
        return some_promise_here;
    })
    .map(function (whatever) {
        // What is the best way to access feed here?
    })
    ....

我找到了一些暗示可能解决方案的回复,但我不能完全确定。

我尝试过 Promise.all().spread(),但我从来没有成功过。

Feed.findAll()
    .map(function (feed) { //  <---- this is what I'm interested in below
        // do some stuff here
        return some_promise_here.then(function(result){
            return { result: result, feed: feed};// return everything you need for the next promise map below.
        });
    })
    .map(function (whatever) {
        // here you are dealing with the mapped results from the previous .map
        // whatever -> {result: [Object],feed:[Object]}
    })

这看起来很像, however you're dealing with a .map call here and seem to want to access the previous result for the same index of the processed array. In that case, not all solutions do apply, and a 似乎是最简单的解决方案:

Feed.findAll().map(function (feed) { 
    // do some stuff here
    return some_promise_here.then(function (whatever) {
        // access `feed` here
    });
})

不过,您也可以申请 ,就像@bluetoft 的回答中概述的那样。