我想在我的循环中打印每一次迭代(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);
});
}
答案 0 :(得分:3)
您需要避免关闭并保存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);
}