可能重複:
How to pass values to a callback function at the time of the request call?如何將遞增的for-loop變量傳遞給node.js中的函數?
我知道這是一個普遍的問題,而不是隻在node.js中我必須將一個變量從for循環傳遞給我想要生成的函數。函數存儲在一個數組中,並且必須記住這些變量。
這是我的例子:
for(var i = 0; i < administratorIds.length; i ++){
adminCallbacks[adminCallbacks.length] = function(callback){
model_user.getById(administratorIds[i], function(user){
administrators[administrators.length] = {name: user.getName()};
callback(null, null);
});
};
}
什麼問題? – Ashe