MCPcopy Index your code
hub / github.com/Lobos/react-ui / formatData

Function formatData

src/Select.js:121–172  ·  view source on GitHub ↗
(data, value = this.state.value)

Source from the content-addressed store, hash-verified

119 }
120
121 formatData (data, value = this.state.value) {
122 if (!Array.isArray(data)) {
123 data = Object.keys(data).map((key) => {
124 return { text: data[key], id: key };
125 });
126 }
127
128 data = data.map((d) => {
129 if (typeof d !== 'object') {
130 return {
131 $option: d,
132 $result: d,
133 $value: d,
134 $filter: d.toLowerCase(),
135 $checked: value.indexOf(d) >= 0,
136 $key: hashcode(d)
137 };
138 }
139
140 // speed filter
141 if (this.props.filterAble) {
142 d.$filter = (Object.keys(d).map((k) => d[k])).join(',').toLowerCase();
143 }
144
145 let val = substitute(this.props.valueTpl, d);
146 d.$option = substitute(this.props.optionTpl, d);
147 d.$result = substitute(this.props.resultTpl || this.props.optionTpl, d);
148 d.$value = val;
149 d.$checked = value.indexOf(val) >= 0;
150 d.$key = d.id ? d.id : hashcode(val + d.$option);
151 return d;
152 });
153
154 if (this.props.groupBy) {
155 let groups = {},
156 groupBy = this.props.groupBy;
157 data.forEach((d) => {
158 let key = d[groupBy];
159 if (!groups[key]) {
160 groups[key] = [];
161 }
162 groups[key].push(d);
163 });
164 data = [];
165 Object.keys(groups).forEach((k) => {
166 data.push(k);
167 data = data.concat(groups[k]);
168 });
169 }
170
171 return data;
172 }
173
174 handleChange (i) {
175 if (this.props.readOnly) {

Callers

nothing calls this directly

Calls 2

hashcodeFunction · 0.90
substituteFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…