【发布时间】:2017-06-06 02:14:32
【问题描述】:
我正在使用visjs Timeline,我正在尝试让一个项目从当前时间扩展 2 天。
var items = new vis.DataSet([{
id = 0,
start = moment(new Date()),
end = moment(new Date()).add(2, 'days')
}, /* And maybe more items */]);
创建新时间线时:
var container = document.getElementById('container');
var timeline = new vis.Timeline(container, items, null);
现在我想更新我的一个项目(比如第一个),以便它始终从当前时间开始。我认为currentTimeTick 会是一个更新的好地方:
timeline.on('currentTimeTick', function() {
var itemData = timeline.itemSet.items[0].data;
itemData.start = moment(); // Set the start to current time
timeline.itemSet.items[0].setData(itemData);
}
当我在 Chrome 中调试时,我看到项目集中的开始时间已更改,但我不确定为什么 UI 没有更新以反映该更改(我希望项目的开始时间与我的当前时间)。
我浏览了源代码,在我看来setData 应该会在时间线上引起redraw,但我认为它不会发生。当我拖动时间线时,它会导致重绘并相应地调整项目的大小。我需要做些什么来强制redraw在这里吗?
【问题讨论】:
标签: javascript vis.js vis.js-timeline