2017-02-28 30 views
0

我使用async.eachSeries遍歷數組。該陣列看起來像:異步在迭代中沒有整個對象

{ filename: '20171-132.pdf', 
    content: [base64 encoded file] 
} 

隨着循環我循環通過項目獲取內容。

async.eachSeries(attach, function(item, callback){ 
    console.log("ITEM", item); 
    var attachment = { 
     filename: item.filename, 
     content: item.content.split("base64")[1], 
     encoding: 'base64' 
    } 

    attachments.push(attachment); 
    callback(); 
}, function(){ 
    console.log("done"); 
}) 

但是,日誌「項目」的,我只有文件名,作爲與結果,該代碼上item.content.split停止,因爲它是不確定的。 任何人有任何想法這裏發生了什麼,我該如何解決這個問題?

回答

1

您正在研究一個對象,而不是一個數組。

{ 
    filename: '20171-132.pdf', 
    content: [base64 encoded file] 
} 

方括號是數組的JSON表示。 因此,如果item看起來像這樣,

[ 
    { 
     filename: '20171-132.pdf', 
     content: [base64 encoded file] 
    } 
] 

然後我猜它會解決你的問題。

+0

是的,我在一秒之前發現了這個錯誤。謝謝! – NVO