dongliao1948 2015-11-05 12:34
浏览 130
已采纳

通过AJAX结果访问DataSet

I am using visjs timeline to make a timeline and I have a button that redraws that timeline on click event. The redrawing is done by getting data from timeline.php using AJAX but the data received doesn't work in DataSet!

Here is what I've got so far:

The function that is triggered when I click on button:

function redrawTL(){
    $.ajax({
        type: "POST", url: "ajax/timeline.php", data: {},
        success: function(data){
            redraw(data);
        }
    });
}

The function that should redraw the timeline assuming I already have set the variables items and tl

function redraw(data){
    console.log(data);
    items = new vis.DataSet([ data ]); // This doesn't!!
    tl.destroy();
    tl = new vis.Timeline(container, items, options);
}

So my question is why it doesn't work?! Knowing that the data is shown in console.

Data is supposed to be filled with the following data:

{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'}

And if I make the redraw function static it works fine.

  • 写回答

1条回答 默认 最新

  • dongtao4787 2015-11-11 14:29
    关注

    After one day of trying i finally came up with the following solution:

                function redrawTL(){
                    $.ajax({
                        type: "POST",url: "ajax/timeline.php", data: {},
                        success: function(data){
                            var result = JSON.parse(JSON.parse(JSON.stringify(data)));
                            items.clear();
                            items.add(result);
                            timeline.fit();
                        }
                    });
                }
    

    It works only if i use JSON.parse over another one!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器