2013-02-22 74 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() 
     // ... 
}); 
相关问题