javascript - 无效开始 "NaN"- timeline vis.js

标签 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: 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

enter image description here

这是我遇到错误的 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/

相关文章:

javascript - Angular 按顺序维护指令列表

javascript - Konva.Node.create 导致 Stage 停止工作

javascript - 弹出的 prettyPhoto 最大宽度和高度太大

javascript - 如何动态添加vue bootstrap下拉列表项?

vue.js - VueJS 评估转义字符

javascript - 数组列表在线显示一个来自json的结果

javascript - 无法将 Vue 数据传递给 Vue 组件

javascript - 在 Vuejs 中使用混合

vuejs2 - Nuxt : Page crashing on page reload

javascript - 如何修复带有复选框的 vue 更新?