我想打印循环中的每次迭代(1,2,3,4,5)。但此时,它仅打印数组的大小 (5)。
for (var key in mapParseJson.background) {
//sequelize
refModelBedrawnins.find({
where: ['POS_TILE_BE_DRAW_IN =? ',mapParseJson.background[key] [0]],
include: [{ model: refModelDrawableObject }]
}).success(function(result) {
// I'd like to print every iteration right here
console.log(key);
});
}
最佳答案
您需要避免关闭并保存 var“key”值:
for (var key in mapParseJson.background) {
//sequelize
(function(k){
refModelBedrawnins.find({
where: ['POS_TILE_BE_DRAW_IN =? ', mapParseJson.background[k] [0]],
include: [{model: refModelDrawableObject}]
}).success(function(result) {
console.log(k);
});
})(key);
}
关于Javascript - for循环仅打印最后一次迭代,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26100791/