本文介绍了.selectAll()到底是做什么的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究示例使用D3.js将XML表示为HTML表" ,以尝试学习 D3.js API.我想我已经掌握了它,但我真的无法理解.selectAll()的功能,并且文档对其帮助不大.

I've been playing around with the example "Using D3.js to present XML as HTML Table", to try and learn the D3.js API. I think I am getting the hang of it, but I can't really understand what the .selectAll() does, and the documentation on it is not very helpful.

如果查看示例,则第17行:var td = tr.selectAll("td").我也可以将其写为tr.selectAll("tr"),它将返回完全相同的表/页面.实际上,我可以编写tr.selectAll("SomethingCompletelyRandom"),它仍然可以工作,但是不能删除.selectAll().

If you look at the example, line 17: var td = tr.selectAll("td"). I can also write this as tr.selectAll("tr") and it will return the exact same table/page. In fact I can write tr.selectAll("SomethingCompletelyRandom") and it will still work, but I can't remove the .selectAll().

这是怎么回事? .selectAll()是做什么的?以及它如何取决于选择器?

What is going on here? What does .selectAll() do? And how does it depend on the selector?

推荐答案

您指向的API链接在上一个选择(它是一个子选择)上使用了selectAll,因此您看待(并且可能会造成混淆.)要查看的文档的相关部分为此处,更笼统地说是此处.

the API link you point to is using selectAll on a previous selection (it is a sub-selection) so it may not make sense for you to look at (and might be confusing.) The relevant part of the documentation to look at would be here, and more generally, the introduction to that selection documentation page, here.

同时使用tdtr的原因是,在这两种情况下,初始选择均不返回任何内容(因为您从中选择的位置tr尚未附加任何内容. )这是选择要创建的内容的标准做法,因为将其扩展到动画并进行更新变得非常重要.

The reason using both td and tr will work here is that the initial selection returns nothing in both of these cases (since the place you are selecting from, tr, has had nothing appended to it yet.) It is standard practice to select what you will be creating, because when extending this to animations and updating it becomes extremely important.

我建议您查看三个小圆圈关于联接的思考教程

这篇关于.selectAll()到底是做什么的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 09:11