javascript有定时器功能吗?
来解释这个问题。我有一个DojoToolkit代码,它每1秒轮询一个打开的monica服务器以在屏幕上显示值。我试图发出警报,每40秒和60秒检查一次数值。因此,我想知道是否有一个函数可以与dojo工具箱的被动轮询一起运行。我尝试过setInterval()和setTimeout(),但是这两种方法都会停止monica服务器的轮询 我的代码是:javascript有定时器功能吗?,javascript,timer,dojo,intervals,Javascript,Timer,Dojo,Intervals,来解释这个问题。我有一个DojoToolkit代码,它每1秒轮询一个打开的monica服务器以在屏幕上显示值。我试图发出警报,每40秒和60秒检查一次数值。因此,我想知道是否有一个函数可以与dojo工具箱的被动轮询一起运行。我尝试过setInterval()和setTimeout(),但是这两种方法都会停止monica服务器的轮询 我的代码是: require(["dojo/dom-attr", "atnf/monica", "dojo/domReady!"], function(domAttr
require(["dojo/dom-attr", "atnf/monica", "dojo/domReady!"], function(domAttr, monica) {
function valCheck(){
}
// The callback is called separately for each point
// that has new data, so we only need to accept the reference to that
// point as an argument.
var pageUpdate = function(pointReference) {
var values = pointReference.latestValue(); //obtain the updated values
domAttr.set("htmlPageDiv", "innerHTML", values.value); //display the moniva value in their corresponding div in the html page
}
};
// We set up the connection to the MoniCA server.
var monicaServer = monica.server({
'webserverName': "some server",
'serverName': "serverName",
"webserverPath": "webServerPath",
'updateInterval': 1000, // in ms
'autoDescriptions': true
});
// Connect to it now, and when that is done, tell it which
// points we want to query.
monicaServer.connect().then(function(serverObj) {
//add monica points to check in the server
var points = monicaServer.addPoints(["some data point", "another data point", "etc."]);
// Tell the server connector which function to call on each
// update, for each point (we use the same callback for each.
for (var i = 0; i < points.length; i++) {
points[i].addCallback(pageUpdate);
}
// Get the descriptions and then start updating.
monicaServer.getDescriptions();
monicaServer.startUpdating();
});
});
require([“dojo/dom attr”,“atnf/monica”,“dojo/domReady!”],函数(domatr,monica){
函数valCheck(){
}
//对每个点分别调用回调
//它有新的数据,所以我们只需要接受对它的引用
//作为论点的论点。
var pageUpdate=函数(点引用){
var values=pointReference.latestValue();//获取更新的值
domAttr.set(“htmlPageDiv”,“innerHTML”,values.value);//在html页面的相应div中显示moniva值
}
};
//我们设置了与MoniCA服务器的连接。
var monicaServer=monica.server({
'webserverName':“某些服务器”,
“服务器名”:“服务器名”,
“webserverPath”:“webserverPath”,
'updateInterval':1000,//以毫秒为单位
“自动描述”:true
});
//现在连接到它,完成后,告诉它是哪个
//我们要查询的点。
monicaServer.connect().then(函数(serverObj){
//添加monica点以签入服务器
var points=monicaServer.addPoints([“一些数据点”、“另一个数据点”、“等等”);
//告诉服务器连接器在每个服务器上调用哪个函数
//更新,对于每个点(我们对每个点使用相同的回调)。
对于(变量i=0;i
除了setTimeout
或setInterval
之外,您还需要什么样的计时器功能?setInterval
不会停止,除非您停止(或关闭页面)。通过使用setInterval
返回的id调用clearInterval
。那么,为什么不在尝试轮询的位置显示代码呢?听起来问题似乎是,使用setInterval
运行的任何代码都会干扰Dojo。也许您需要找出Dojo是否具有执行所需操作的功能。尝试以下操作:setInterval(function(){alert(“Hello”);},3000);
除了setTimeout
或setInterval
之外,您还需要什么样的计时器函数?setInterval
不会停止,除非您停止(或关闭页面)。通过使用setInterval
返回的id调用clearInterval
。那么,为什么不在尝试轮询的位置显示代码呢?听起来问题似乎是,使用setInterval
运行的任何代码都会干扰Dojo。也许您需要找出Dojo是否具有执行所需操作的功能。尝试以下操作:setInterval(函数(){alert(“Hello”);},3000);