我的问题是变量范围、async.mapSeries 和嵌套回调函数。我需要迭代一个集合并根据集合中的值调用一个存储过程。
到目前为止,我的代码如下
var _var1 = "";
LoadData(sp, callback)
{
//mysql stuff
connection.connect();
var query = connection.query(sp, function(err, rows, fields){
if (err) console.log(err);
connection.end();
callback(rows[0]);
});
}
otherfunction() {
//retdata returned from another function
async.mapSeries(retdata,function(rd, rdCb){
LoadData(options, function (row) {
var _content = new Buffer(row[0].content, 'base64').toString('ascii');
//can't get _content to the callback, and _var1 isn't in scope here
});
//next
rdCb();
},function(err,results){
//need _content accessible here to iterate through data
});
有什么想法吗?