我需要其他{}只能工作一次。我怎么能这样做?谢谢。
setInterval(function(){
mysqlConnection.query('SELECT `dog` FROM `pets` WHERE `name`=`nice`', function(err, row, fields) {
var nice_pet = (row[0].dog);
mysqlConnection.query('SELECT `food` FROM `info`', function(err, row, fields) {
mysqlConnection.query('SELECT COUNT(Distinct food) AS DistinctCount FROM `something', function(err, row, fields) {
var check = row[0].DistinctCount;
if (check <= 10) {
// Do it many times
} else {
// Do it only once if it goes to here
}
})
})
})
}, 1000);
答案 0 :(得分:2)
制作一个标志,并将其用作else if
var once = false;
setInterval(function(){
mysqlConnection.query('SELECT `dog` FROM `pets` WHERE `name`=`nice`', function(err, row, fields) {
var nice_pet = (row[0].dog);
mysqlConnection.query('SELECT `food` FROM `info`', function(err, row, fields) {
mysqlConnection.query('SELECT COUNT(Distinct food) AS DistinctCount FROM `something', function(err, row, fields) {
var check = row[0].DistinctCount;
if (check <= 10) {
// Do it many times
} else if(!once) {
once = true;
// Do it only once if it goes to here
}
})
})
})
}, 1000);