我有一个树形布局。如图中JSBin http://jsbin.com/AbOmAZE/11/更新可视化背后的数据
在与一个节点相关联的文字点击事件,我想可视化背后的数据进行更新(我需要更新树布局背后的数据,因为它是用作接口)。我已经实现了重画和click事件,但是我不知道如何仅仅通过知道从click函数返回的当前选择来更新数据。
node.append("text")
.text(function(d){ return d.name; })
.on('click', function(d){
var result = prompt('Change the name of the node',d.name)
if(!result) {
d.name = result; // !!! This is where the problem is.
}
console.log(d)
draw(); //This redraws the graph
})
请参考上面发布的JSBin。
非常感谢您的帮助。视图如何通过底层数据进行更新是很棒的。 然而,我仍然面临的问题是将绑定的数据放回到我的数据数组中。我需要这个,所以我可以将更改写回到我的数据库。 – Paul