我有一個樹形佈局。如圖中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