4
在我的d3js應用程序中,當用戶將鼠標懸停在特定的圓上時,我將其放大。這沒有問題。同時,我想選擇「所有其他」,並使它們變小。什麼是抓住「所有其他圈子」的好詢問?是否有一個選擇查詢來抓取除當前所選內容之外的所有內容?
在我的d3js應用程序中,當用戶將鼠標懸停在特定的圓上時,我將其放大。這沒有問題。同時,我想選擇「所有其他」,並使它們變小。什麼是抓住「所有其他圈子」的好詢問?是否有一個選擇查詢來抓取除當前所選內容之外的所有內容?
根據您的需要,您可以使用selection.filter或常用的selection.select的鮮爲人知的功能形式。 http://jsfiddle.net/9TmXs/
.on('click', function (d) {
// The clicked element returns to its original size
d3.select(this).transition() // ...
var circles = d3.selectAll('svg circle');
// All other elements resize randomly.
circles.filter(function (x) { return d.id != x.id; })
.transition() // ...
});
另一種通用方法,比較DOM元素本身:
如果您在使用key functions,這是推薦的方式綁定你的DOM元素的數據,那麼你可以選擇的主要篩選http://jsfiddle.net/FDt8S/
.on('click', function (d) {
// The clicked element returns to its original size
d3.select(this).transition() // ..
var self = this;
var circles = d3.selectAll('svg circle');
// All other elements resize randomly.
circles.filter(function (x) { return self != this; })
.transition()
// ...
});