我不知道为什么,但是当我尝试打电话时
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
脚本中记录了正在发生的事情。它开始记录开始和结束日期,然后抛出 error 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()
创建了一个对象,而不是一个数字,而您的函数期望日期是一个数字。因此 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 + '"');
}
关于javascript - 无效开始 "NaN"- timeline vis.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51359560/