Node.js 函数结果外部循环的节点js
我在for循环中使用一个函数。我无法导出函数的结果 我想将结果导出到数据数组。我怎么做Node.js 函数结果外部循环的节点js,node.js,Node.js,我在for循环中使用一个函数。我无法导出函数的结果 我想将结果导出到数据数组。我怎么做 function opPerformance(callback) { var data = []; dbConn.connect(function(err) { var request = new sql.Request(dbConn); request.query('select * from Kullanici ORDER BY Kullanici_Adi
function opPerformance(callback) {
var data = [];
dbConn.connect(function(err) {
var request = new sql.Request(dbConn);
request.query('select * from Kullanici ORDER BY Kullanici_Adi ASC ').then(function(recordset) {
var results = [];
for (var i in recordset.recordset) {
data[i] = {
kullanici_adi:recordset.recordset[i].Kullanici_Adi,
performance:'0'
};
opPerformanceData(recordset.recordset[i].Kullanici_Adi, function ( result ){
data[i]['performance'] = result; // This is not working, I can not get the end out.
console.log(result); // This works.
});
}
callback(data);
});
});
};
您传递的回调函数opPerformanceData中可能存在重复,该回调函数将异步执行,因此,当您调用回调(data)时,数据将为空