gpt4 book ai didi

.net - Node JS setInterval。 TypeError : Cannot read property 'apply' of undefined

转载 作者:行者123 更新时间:2023-12-03 09:02:42 25 4
gpt4 key购买 nike

我是Nowfal,一位C#程序员。我是Node JS的新手。
当我创建一个函数并在setInterval内部给出一个错误时,
TypeError:无法读取未定义的属性“应用”

在包装器上[作为_onTimeout](timers.js:274:13)

在Timer.listOnTimeout(timers.js:119:15)

我的代码页如下

页面1(Server.js)

var db = require('./dbConnect.js');
var ins = require('./dbInsert.js');

var tagId = [];
var schoolInfoId = [];
var imeNo = [];
var totalRows = 0;

function ViewQuery() {
var mysql = db.mysql;
var connection = db.createMyConnection();


connection.connect();


var mycommand = "SELECT t.skha_tag_id_no,s.skha_school_info_id,a.skha_out_device_imeno" +
" FROM skha_tag t INNER JOIN skha_student_info s on skha_tag_id = skha_student_tag_id_no " +
" INNER JOIN skha_student_school_attendance a on a.skha_student_info_id = s.skha_student_info_id" +
" WHERE DATE(skha_student_in_time) = CURDATE() AND skha_student_out_time IS NULL and skha_out_status = 1 ";

connection.query(mycommand, function (err, rows) {
if (!err) {

var result;
for (i = 0; i < rows.length; i++) {
totalRows++;

result = rows[i];

tagId.push(result['skha_tag_id_no']);
schoolInfoId.push(result['skha_school_info_id']);
imeNo.push(result['skha_out_device_imeno']);

}


for (i = 0; i < totalRows; i++) {
ins.insertDB(tagId[i], schoolInfoId[i], imeNo[i]);
}

}
else
console.log('Error while performing Query.');
});

connection.end();

};

setInterval(ViewQuery(),30000); //Error Generating from here

页面2(dbConnect.js)
var mysql = require('mysql');

exports.createMyConnection = function createMyConnection() {
var connection = mysql.createConnection( {
host : '192.168.0.175',
user : 'ss_user',
password : 'df33-ccff2188',
database : 'shkaliasdb',
multipleStatements: true
});
return connection;
}

exports.mysql = mysql;

页面3(dbInsert.js)
var db = require('./dbConnect.js');

var logOutTimeInterval = 5;
exports.insertDB = function (RFID, schoolID, imei) {

var mysql = db.mysql;
var connection = db.createMyConnection();

connection.connect();
console.log('IMEI : ' + imei);
console.log(RFID);



str = "SET @OutStatus=0;SET @logOutTime=0;call out_mark_save_two_device('" + RFID + "'," + schoolID + "," + logOutTimeInterval + ",@OutStatus,@logOutTime," + imei + ")";

console.log(str);


connection.query(str, function (err, rows, fields) {//, fields
if (err)
console.log('Error while performing Query.' + err);
else {
console.log(rows[0]);

}
});

connection.end();


};

第一次代码正常工作,然后显示错误消息,计时器不起作用。

请给我任何解决方案...
提前致谢..

最佳答案

显示来自timers.js的代码。
您从 undefined object 调用“应用”方法。方法“应用”工作

关于.net - Node JS setInterval。 TypeError : Cannot read property 'apply' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31605654/

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