2013-02-22 45 views

回答

5

根據您的需要,您可以使用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() 
     // ... 
}); 
相關問題