<分区>
我有这个递归函数,我需要在函数完成后返回一些数据。
// Set Up my Database paramaters
var coachdb = new AWS.DynamoDB({
...
});
// This tracks the array index of the current parameter.
var pos = 0;
function callback(err, data) {
if (err) {
console.log(err, err.stack);
} else if (data.Items.length > 0) {
//return data.Items // Where I need something here to return data
} else if (++pos < params.length) { // Increment the index.
coachdb.query(params[pos], callback); // Recursive call.
}
}
coachdb.query(params[pos], callback); // Kick off the series of calls
函数内的一切都运行良好。我正在查询我的数据库,遍历可能的参数直到找到正确的参数,然后函数结束。
但是我不确定如何将数据传递到函数外部。任何帮助将不胜感激。