gpt4 book ai didi

Javascript SetInterval 仅使用一次 Else

转载 作者:行者123 更新时间:2023-12-02 15:46:58 25 4
gpt4 key购买 nike

我只需要 else {} 工作一次。我怎样才能做到这一点?谢谢。

    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);

最佳答案

创建一个标志,并将其用作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);

关于Javascript SetInterval 仅使用一次 Else,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32127774/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com