我使用visjs timeline制作时间轴,我有一个按钮,可以在点击事件上重绘该时间轴。重绘是通过使用AJAX从timeline.php获取数据完成的,但收到的数据在DataSet中不起作用!
这是我到目前为止所得到的:
单击按钮时触发的功能:
function redraw(data){
console.log(data);
items = new vis.DataSet([ data ]); // This doesn't!!
tl.destroy();
tl = new vis.Timeline(container, items, options);
}
应该重绘时间线的函数,假设我已经设置了变量items和tl
{id: 0, content: '07:10:12', start: today.clone().add(25606, 'seconds'), 'className': 'tmstyle'},
{id: 1, content: '00:40:06', start: today.clone().add(56563, 'seconds'), 'className': 'arretNU'},
{id: 2, content: '00:01:07', start: today.clone().add(63312, 'seconds'), 'className': 'arretNU'},
{id: 3, content: '00:00:16', start: today.clone().add(63389, 'seconds'), 'className': 'arretNU'}
所以我的问题是为什么它不起作用?!知道数据显示在控制台中。
数据应该填充以下数据:
current_output = ['test1.txt StatusCode: 123', 'test2.txt StatusCode: 726', 'test1.txt CompanyID: abc']
d = dict()
order = []
for item in current_output:
k,v = item.split(' ', 1)
if k not in order:
order.append(k)
d[k] = d.get(k, []) + [v]
desired_output = ["%s %s" % (k, ' '.join(d[k])) for k in order]
print desired_output
如果我将重绘功能设为静态,它可以正常工作。
答案 0 :(得分:0)
经过一天的尝试,我终于找到了以下解决方案:
setwd("where is your folder")
#
#List file subdirectories
folders<- list.files(path = "yourfolder")
#
#Get all files...
files <- rep(NA,0)
for(i in c(1:length(folders)))
{
files.i <- list.files(path = noquote(paste("yourfolder/",folders[i], "/", sep = "")))
n <- length(files.i)
files.i <- paste(folders[i], files.i, sep = "/")
files <- c(files, files.i)
}
#
#
#Read first data file (& add file name as separate column)
T1 <- read.delim(paste("yourfolder/", files[1], sep = ""), sep = "", header=TRUE)
T1 <- cbind(T1, "FileName" = files[1])
只有当我使用JSON.parse而不是另一个时才有效!