使用以下数据:
var days = ["Sun", "Mon", "Tues", "Wed", "Thur", "Fri", "Sat"];
我需要将html结构变为:
<div>
<input id="day0" type="checkbox">
<label for="day0">Sun</label>
<input id="day1" type="checkbox">
<label for="day1">Mon</label>
.... Etc
</div>
目前我目前失败的解决方案是:
var selection = d3.select("div");
var enter = selection.selectAll("input").data(days).enter()
enter.append("input")
.attr("type","checkbox")
.attr("id",function(d,i){ return "day"+i;})
enter.append("label")
.attr("for",function(d,i){ return "day"+i;})
.text(function(d,i){return daysAbbr[i];})
这给了我一个不正确的dom:
<div>
<input id="day0" type="checkbox">
<input id="day1" type="checkbox">
.... Etc
<label for="day0">Sun</label>
<label for="day1">Mon</label>
.... Etc
</div>
我将如何创建所有这些相邻的兄弟姐妹?