使用D3

时间:2016-11-21 21:31:20

标签: javascript html d3.js

我有以下html结构

<thead class="table-header">   
  <tr>
    <th><div class="th-inner">a</th>
    <th><div class="th-inner">b</th>
    <th><div class="th-inner">c</th>   
  </tr> 
</thead>

我想在第三阶段添加div,但是基于具有三个元素的简单数据数组(mydata = [&#39; x&#39;,&#39; y&#39; ,&#39; z&#39;])。

我试过以下但它似乎没有效果:

cells = d3.select('root').select('thead.table-header tr')
   .selectAll('div.th-inner').data(mydata)
   .selectAll('div.th-but').data(function(d,i){return d;});

cells.enter().append('div').classed('th-but', true);

我错过了什么吗?我是否正朝着解决方案的方向前进?

1 个答案:

答案 0 :(得分:1)

如果您希望UILabel成为viewDidLoad的兄弟,则需要将其附加到其父元素div.th-but。您可以使用div.th-inner,或直接选择父元素。

th

insert

jsfiddle