(value = [], initial)
| 349 | } |
| 350 | |
| 351 | setValue (value = [], initial) { |
| 352 | value = this.applyConstFilter(value) |
| 353 | /* Make sure value has between minItems and maxItems items in it */ |
| 354 | value = this.ensureArraySize(value) |
| 355 | |
| 356 | const serialized = JSON.stringify(value) |
| 357 | if (serialized === this.serialized) { |
| 358 | if (initial) { |
| 359 | this.refreshValue(initial) |
| 360 | } |
| 361 | return |
| 362 | } |
| 363 | |
| 364 | value.forEach((val, i) => { |
| 365 | if (this.rows[i]) { |
| 366 | /* TODO: don't set the row's value if it hasn't changed */ |
| 367 | this.rows[i].setValue(val, initial) |
| 368 | } else if (this.row_cache[i]) { |
| 369 | this.rows[i] = this.row_cache[i] |
| 370 | this.rows[i].setValue(val, initial) |
| 371 | this.rows[i].container.style.display = '' |
| 372 | if (this.rows[i].tab) this.rows[i].tab.style.display = '' |
| 373 | this.rows[i].register() |
| 374 | this.jsoneditor.trigger('addRow', this.rows[i]) |
| 375 | } else { |
| 376 | const editor = this.addRow(val, initial) |
| 377 | this.jsoneditor.trigger('addRow', editor) |
| 378 | } |
| 379 | }) |
| 380 | |
| 381 | for (let j = value.length; j < this.rows.length; j++) { |
| 382 | this.destroyRow(this.rows[j]) |
| 383 | this.rows[j] = null |
| 384 | } |
| 385 | this.rows = this.rows.slice(0, value.length) |
| 386 | |
| 387 | /* Set the active tab */ |
| 388 | const row = this.rows.find(row => row.tab === this.active_tab) |
| 389 | let newActiveTab = typeof row !== 'undefined' ? row.tab : null |
| 390 | if (!newActiveTab && this.rows.length) newActiveTab = this.rows[0].tab |
| 391 | |
| 392 | this.active_tab = newActiveTab |
| 393 | |
| 394 | this.refreshValue(initial) |
| 395 | this.refreshTabs(true) |
| 396 | this.refreshTabs() |
| 397 | |
| 398 | this.onChange() |
| 399 | |
| 400 | /* TODO: sortable */ |
| 401 | } |
| 402 | |
| 403 | setButtonState (element, display) { |
| 404 | const buttonStateMode = this.options.button_state_mode || this.jsoneditor.options.button_state_mode |
no test coverage detected