D3.js 在这个D3示例中,点击事件是否会改变源json?

D3.js 在这个D3示例中,点击事件是否会改变源json?,d3.js,D3.js,我不明白在这个例子中单击事件做了什么。它正在修改原始的根JSON数据结构。这是否表明节点数据结构指向源数据结构根,而不是创建根的副本并使用副本不变性 var i = 0, duration = 750, root; 是的,它正在修改root,而不是它的副本,因为传递给click的d只是对root的引用。如果添加一个console.logroot,您可以测试这一点;在单击的末尾 以下是单击根节点4次后记录的内容: Object { name: "flare", x0: 380,

我不明白在这个例子中单击事件做了什么。它正在修改原始的根JSON数据结构。这是否表明节点数据结构指向源数据结构根,而不是创建根的副本并使用副本不变性

var i = 0,
    duration = 750,
    root;

是的,它正在修改root,而不是它的副本,因为传递给click的d只是对root的引用。如果添加一个console.logroot,您可以测试这一点;在单击的末尾

以下是单击根节点4次后记录的内容:

Object { name: "flare", x0: 380, y0: 0, depth: 0, x: 380, y: 0, id: 11, _children: Array[10] }
Object { name: "flare", x0: 380, y0: 0, depth: 0, x: 380, y: 0, id: 11, _children: null, children: Array[10] }
Object { name: "flare", x0: 380, y0: 0, depth: 0, x: 380, y: 0, id: 11, _children: Array[10] }
Object { name: "flare", x0: 380, y0: 0, depth: 0, x: 380, y: 0, id: 11, _children: null, children: Array[10] }
演示:

Object { name: "flare", x0: 380, y0: 0, depth: 0, x: 380, y: 0, id: 11, _children: Array[10] }
Object { name: "flare", x0: 380, y0: 0, depth: 0, x: 380, y: 0, id: 11, _children: null, children: Array[10] }
Object { name: "flare", x0: 380, y0: 0, depth: 0, x: 380, y: 0, id: 11, _children: Array[10] }
Object { name: "flare", x0: 380, y0: 0, depth: 0, x: 380, y: 0, id: 11, _children: null, children: Array[10] }