javascript - How to set the last option from a drop-down list as selected using D3.js -
i have drop-down list dates options in it:
<select id="dateselector"> <option value="2016-01-01">Январь 2016</option> <option value="2016-02-01">Февраль 2016</option> <option value="2016-03-01">Март 2016</option> </select>
i need set last date list (the recent) selected one. i've managed specifying date manually. how can automatically in case if more dates appear in list options in future?
d3.select("select#dateselector") .selectall("option") .data(uniquedates) .enter() .append("option") .text(function(d) { return formatru(new date(d)); }) .attr("value", function(d) { return d; }) .property("selected", function(d) { return d === "2016-03-01"; });
you based on index of datum instead. let n = uniquedates.length
, use:
.property("selected", function(d, i) { return == n-1; })
Comments
Post a Comment