请帮助我理解select()和selectAll()之间的区别, [英] Please help me understand the difference between the select() and selectAll()
问题描述
我觉得我误解了一些非常基本的,这两者之间的区别是什么?
I feel I misunderstand something very basic, what is the difference between those two ?
我没有得到第二个不追加ap标签的原因对我来说。
I didn't get the reason why the second one will not append a p tag for me.
divSelection = d3.select('#div-vis').selectAll('p').data(['dummy']).enter().append('p');
divSelection = d3.select('#div-vis').select('p').data(['dummy']).enter().append('p');
推荐答案
从嵌套选择:
嵌套选择有另一个微妙但关键副作用:它为每个组设置父节点。父节点是选择项上的隐藏属性,用于确定在哪里附加输入元素。 ... select和selectAll之间有一个重要的区别:select保留现有分组,而selectAll创建一个新分组。因此调用select会保留数据,索引,甚至是原始选择的父节点!
Nesting selections has another subtle yet critical side-effect: it sets the parent node for each group. The parent node is a hidden property on selections that determines where to append entering elements. … There is an important difference between select and selectAll: select preserves the existing grouping, whereas selectAll creates a new grouping. Calling select thus preserves the data, index and even the parent node of the original selection!
当你说 d3.select(#vis)
,选择的父节点仍然是文档元素。然后,当您说 selectAll(p)
时,您将父节点定义为先前选择的#vis元素,因为selectAll是嵌套运算符。这只发生在selectAll而不是选择。
When you say d3.select("#vis")
, the parent node of the selection is still the document element. When you then say selectAll("p")
, you define the parent node as the previously-selected #vis element, because selectAll is a nesting operator. That only happens with selectAll and not select.
这篇关于请帮助我理解select()和selectAll()之间的区别,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!