Javascript 无效的开始“;“南”时间轴vis.js
我不知道为什么但是当我试着打电话的时候Javascript 无效的开始“;“南”时间轴vis.js,javascript,vue.js,vuejs2,vis.js,vis.js-timeline,Javascript,Vue.js,Vuejs2,Vis.js,Vis.js Timeline,我不知道为什么但是当我试着打电话的时候 this.$refs.timeline.on('rangechange', function (start, end, byUser, event) { console.log('timechanged...') }) 每次错误:无效开始“NaN”时,我都会遇到此错误 我在谷歌上搜索解决方案,但什么也没找到 以下是时间线的选项: timeline: { stack: true, start: new Date(), end
this.$refs.timeline.on('rangechange', function (start, end, byUser, event) {
console.log('timechanged...')
})
每次错误:无效开始“NaN”
时,我都会遇到此错误
我在谷歌上搜索解决方案,但什么也没找到
以下是时间线的选项:
timeline: {
stack: true,
start: new Date(),
end: new Date(1000 * 60 * 60 * 24 + (new Date()).valueOf()),
min: new Date(2018, 0, 1),
max: new Date(2019, 0, 1),
zoomMin: 1000 * 27 * 24 * 24, // if you want to zoom more in then lower the 27
zoomMax: 1000 * 60 * 60 * 24 * 31 * 3,
orientation: 'top'
}
我已经在vis.js
脚本中记录了正在发生的事情。它开始记录开始和结束日期,然后抛出错误NaN
这里是vis.js
脚本代码,我在这里得到了错误
console.log('START', start)
console.log('END', end)
var newStart = start != null ? util.convert(start, 'Date').valueOf() : this.start,
newEnd = end != null ? util.convert(end, 'Date').valueOf() : this.end,
max = this.options.max != null ? util.convert(this.options.max, 'Date').valueOf() : null,
min = this.options.min != null ? util.convert(this.options.min, 'Date').valueOf() : null,
diff;
// check for valid number
if (isNaN(newStart) || newStart === null) {
throw new Error('Invalid start "' + start + '"');
}
if (isNaN(newEnd) || newEnd === null) {
throw new Error('Invalid end "' + end + '"');
}
有人知道如何解决这个问题吗?谢谢。这是因为
new Date()
创建的是一个对象,而不是一个数字,并且您的函数希望Date是一个数字。因此NaN
=不是一个数字
[编辑]将测试逻辑更改为:
console.log('START');
console.dir(start);
console.log('END');
console.dir(end);
var newStart = !isNaN(start) ? util.convert(start, 'Date').valueOf()
: this.start
,newEnd = !isNaN(end) ? util.convert(end, 'Date').valueOf()
: this.end
,max = this.options.max != null ? util.convert(this.options.max, 'Date').valueOf() : null
,min = this.options.min != null ? util.convert(this.options.min, 'Date').valueOf() : null
,diff;
//check for valid number
if ( isNaN(newStart) ) {
throw new Error('Invalid start "' + start + '"');
}
if ( isNaN(newEnd) ) {
throw new Error('Invalid end "' + end + '"');
}
尝试使用Date.now()-返回自1970年1月1日以来的毫秒数
比如:
timeline: {
stack: true,
start: Date.now(),
end: Date.now() + (1000 * 60 * 60 * 24),
min: new Date(2018, 0, 1),
max: new Date(2019, 0, 1),
zoomMin: 1000 * 27 * 24 * 24, // if you want to zoom more in then lower the 27
zoomMax: 1000 * 60 * 60 * 24 * 31 * 3,
orientation: 'top'
}
如果开始
|结束
应该是日期对象(而不是数字),您可以执行以下操作:
timeline: {
stack: true,
start: new Date(),
end: new Date(Date.now() + (1000 * 60 * 60 * 24)),
min: new Date(2018, 0, 1),
max: new Date(2019, 0, 1),
zoomMin: 1000 * 27 * 24 * 24, // if you want to zoom more in then lower the 27
zoomMax: 1000 * 60 * 60 * 24 * 31 * 3,
orientation: 'top'
}
Try(new Date()).getTime()将返回一个纪元时间,从1970年起为毫秒。它不是这样工作的。我已经用图片和vis.js代码更新了我的问题,在那里我得到了错误。你能看一下吗?@Reo93,不要与null比较,而是用“isNaN(ref)”替换你的测试,其中ref是要测试的项。如果isNaN返回true,那么参数不是一个包含“null”的数字。你对tests和ref是什么意思?我做的。我正在制作一个vue应用程序,所以首先我使用了vue2vis,我认为该软件包不起作用。所以我需要用普通的vis.js实现它。不过还是要谢谢你!它不是那样工作的。我已经用图片和vis.js代码更新了我的问题,在那里我得到了错误。你能看一下吗?