如果从API调用中更改某些内容,我想检查所有秒。
我在这里得到数据
var data= [];
$.getJSON(url, function(results){
var history = results.history;
$.each(history, function(index) {
data.push(history[index].currenthashrate);
});
});
数据在那里......
比我构建一个“if”来检查新旧数据
newdata = data;
if(newdata.length == olddata.length) {
console.log("old old old old old old old old old old old old")
} else {
console.log("new new new new new new new new new new new new")
drawChart(data, onlinedata, timestampdata);
console.log('new');
console.log(newdata.length);
console.log('old');
console.log(olddata.length);
olddata = data;
}
所以我之前尝试给newdata并使用olddata.length检查newdata.length。如果匹配,他会垃圾旧的旧...
如果不匹配,请发送新的新新邮件并将之前获得的数据提供给图表。
但是idk为什么,olddata的长度= 39而newdata = 0 ...但为什么呢?我之前给他们一个相同的数据,如果是,一个在if。
我只想再次绘制图表,如果发生了变化......
这是完整的代码
setInterval(function() {
getChartData();
}, 10000);
var olddata = '';
function getChartData() {
url = 'myapiurl.com....';
var data= [];
$.getJSON(url, function(results){
var history = results.history;
$.each(history, function(index) {
data.push(history[index].currenthashrate);
});
});
newdata = data;
if(newdata.length == olddata.length) {
console.log("old old old old old old old old old old old old")
} else {
console.log("new new new new new new new new new new new new")
drawChart(data, onlinedata, timestampdata);
console.log('new');
console.log(newdata.length);
console.log('old');
console.log(olddata.length);
olddata = data;
}
}