2013-03-31 19 views
0

首先,我創建一個選區併爲其添加一些內容。我已經剝離下來的可讀性:如何執行d3嵌套的數據連接,其中子引用父數據的位置?

arcData = [ 
    {data: [{label: "first"}], otherProp: value}, 
    {data: [{label: "second"}], otherProp: value}]; 

arcSelection = svg.selectAll("arc").data(arcData); 

arcSelection.enter().append("g").append("path").attr("d", myArcDefinition); 

我嘗試添加使用從父數據嵌套的選擇:

arcDataSelection = arcSelection.selectAll("text").data(function(singleArc, arcIndex) { 
    return singleArc; 
}); 
arcDataSelection.enter().append("text").text(function(d) { 
    return d.data.label; 
}); 

但沒有text對象在DOM創建。我怎樣才能正確地創建一個使用父數據的嵌套選擇中的元素?

我試圖按照這裏顯示的模式(S):http://bost.ocks.org/mike/nest/

回答

0

使用嵌套的選擇,你需要有嵌套數據。您傳入一維數組(即不嵌套)。再看看你鏈接的例子 - 那裏使用的數據是一個二維數組。

+0

謝謝。當然! – tnunamak