select()和selectAll()之间有什么区别 [英] What is the difference between select() and selectAll()

查看:204
本文介绍了select()和selectAll()之间有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

select()和selectAll()有什么区别?

What is the difference between select() and selectAll()?

为什么第二个不附加ap标签?

Why doesn't the second one append a p tag?

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而不是select。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆