2016-04-09 739 views

回答

1

如果你指的是:http://vuejs.org/examples/tree-view.html

有这个没有什么特别的方法nessessary。你会简单地用新的数据替换数据:

var demo = new Vue({ 
    el: '#demo', 
    data: { 
    treeData: data 
    }, 
    methods: { 
    //call this method e.g. from a buttons click event. 
    flushtree: function() { 
     this.treeData = newData // get new Data from somehwere. 
    } 
    } 
}) 
+0

感谢您的解决方案。 顺便说一句如何停止添加子节点在某些时刻(禁用dbl点击事件或停止某些子节点的递归行为)? –

+0

我会添加一个道具'深度'并且在每次递归调用时增加它。然后检查点击处理程序,如果深度<10或某些东西,取决于你的条件是什么。 –

0

我修改后的代码片段:

if(demo!=null) { 
    demo.flushtree(tableJson); 
} else { 
    demo = new Vue({ 
    data: { 
    treeData: tableJson 
    }, 
    methods: { 
     flushtree: function(newData) { 
     this.treeData = newData; 
    } 
} 
}) 
demo.$mount('#demo'); 
} 

谢谢:)