2013-03-30 68 views
0

當我想打電話給seqEach上two_objects的情況下,我該怎麼辦:如何在異步處理函數中解析對象?

Seq() 
    .seq(function() { 
     pivotal.getProjects(this); 
    }) 
    .flatten() 
    .seqEach(function(data) { 
     var project_ids = data.project.map(function(x) { return parseInt(x.id); }) 
     console.log('project_ids: '.red + project_ids); 
     // pivotal.getStories(project.id, { filter: "state:finished" }, this); 
    }) 
    .seq(function() { 
     var aggregatedStories = []; 
     Hash.map(this.args, (function(arg) { 
      aggregatedStories.push(arg[0]); 
     })); 
     res.send(aggregatedStories); 
    }); 

日誌:

project_ids: 644511,340755 

pivotal.getProjects(this);

回報像

{"project": { "id": 644511}, { "id": 340755} }

所以問題是因爲data應該換成data.project但是怎麼做呢?

回答

1

所以問題是因爲data應該被替換爲data.project但是怎麼做呢?

要麼你增加您的seqEach回調的頂部行data = data.project;,或者你喜歡注入

.map(function(d) { return d.project; }) 

映射功能到您的鏈條。或者你只需​​更改pivotal.getProjects方法...

相關問題