1 | import { isArray } from "d3-let";
|
2 | import { select } from "d3-selection";
|
3 | import { createValueType } from "./type";
|
4 |
|
5 | export default createValueType({
|
6 | value(value) {
|
7 | var sel = this.sel,
|
8 | options = sel.selectAll("option"),
|
9 | values = value,
|
10 | opt;
|
11 |
|
12 | if (arguments.length) {
|
13 | if (!isArray(values)) values = [value || ""];
|
14 | options.each(function() {
|
15 | opt = select(this);
|
16 | value = opt.attr("value") || "";
|
17 | opt.property("selected", values.indexOf(value) > -1);
|
18 | });
|
19 | } else {
|
20 | values = [];
|
21 | options.each(function() {
|
22 | opt = select(this);
|
23 | if (opt.property("selected")) values.push(opt.attr("value") || "");
|
24 | });
|
25 | if (sel.property("multiple")) return values;
|
26 | else return values[0] || "";
|
27 | }
|
28 | }
|
29 | });
|