Fixed switching from object/array to auto/string and vice versa
This commit is contained in:
parent
ebcfa301ad
commit
0ea0059696
|
@ -332,6 +332,7 @@ Node.prototype.setValue = function(value, type) {
|
||||||
var childValue, child, visible;
|
var childValue, child, visible;
|
||||||
var i, j;
|
var i, j;
|
||||||
var notUpdateDom = false;
|
var notUpdateDom = false;
|
||||||
|
var previousChilds = this.childs;
|
||||||
|
|
||||||
this.type = this._getType(value);
|
this.type = this._getType(value);
|
||||||
|
|
||||||
|
@ -431,15 +432,56 @@ Node.prototype.setValue = function(value, type) {
|
||||||
else {
|
else {
|
||||||
// value
|
// value
|
||||||
this.hideChilds();
|
this.hideChilds();
|
||||||
this.childs = undefined;
|
|
||||||
|
delete this.append;
|
||||||
|
delete this.showMore;
|
||||||
|
delete this.expanded;
|
||||||
|
delete this.childs;
|
||||||
|
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// recreate the DOM if switching from an object/array to auto/string or vice versa
|
||||||
|
// needed to recreated the expand button for example
|
||||||
|
if (Array.isArray(previousChilds) !== Array.isArray(this.childs)) {
|
||||||
|
this.recreateDom();
|
||||||
|
}
|
||||||
|
|
||||||
this.updateDom({'updateIndexes': true});
|
this.updateDom({'updateIndexes': true});
|
||||||
|
|
||||||
this.previousValue = this.value;
|
this.previousValue = this.value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the DOM of this node and it's childs and recreate it again
|
||||||
|
*/
|
||||||
|
Node.prototype.recreateDom = function() {
|
||||||
|
var table = this.dom.tr ? this.dom.tr.parentNode : undefined;
|
||||||
|
var lastTr;
|
||||||
|
if (this.expanded) {
|
||||||
|
lastTr = this.getAppendDom();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
lastTr = this.getDom();
|
||||||
|
}
|
||||||
|
var nextTr = (lastTr && lastTr.parentNode) ? lastTr.nextSibling : undefined;
|
||||||
|
|
||||||
|
// hide current field and all its childs
|
||||||
|
this.hide({ resetVisibleChilds: false });
|
||||||
|
this.clearDom();
|
||||||
|
|
||||||
|
// create new DOM
|
||||||
|
if (table) {
|
||||||
|
if (nextTr) {
|
||||||
|
table.insertBefore(this.getDom(), nextTr);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
table.appendChild(this.getDom());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.showChilds();
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get value. Value is a JSON structure
|
* Get value. Value is a JSON structure
|
||||||
* @return {*} value
|
* @return {*} value
|
||||||
|
|
|
@ -200,12 +200,11 @@ treemode.set = function (json, name) {
|
||||||
};
|
};
|
||||||
|
|
||||||
treemode.update = function (json) {
|
treemode.update = function (json) {
|
||||||
// TODO
|
this.content.removeChild(this.table); // Take the table offline
|
||||||
// this.content.removeChild(this.table); // Take the table offline
|
|
||||||
|
|
||||||
this.node.setValue(json);
|
this.node.setValue(json);
|
||||||
|
|
||||||
// this.content.appendChild(this.table); // Put the table online again
|
this.content.appendChild(this.table); // Put the table online again
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -61,7 +61,7 @@
|
||||||
"arrayGrow": [1, 2, 3],
|
"arrayGrow": [1, 2, 3],
|
||||||
"arrayShrink": [1, 2, 3],
|
"arrayShrink": [1, 2, 3],
|
||||||
"autoToArray": 123,
|
"autoToArray": 123,
|
||||||
"ArrayToAuto": [1, 2, 3],
|
"arrayToAuto": [1, 2, 3],
|
||||||
"objectGrow": {"a": "b", "c": "d"},
|
"objectGrow": {"a": "b", "c": "d"},
|
||||||
"objectShrink": {"a": "b", "c": "d"},
|
"objectShrink": {"a": "b", "c": "d"},
|
||||||
"objectToArray": {"a": "b", "c": "d"},
|
"objectToArray": {"a": "b", "c": "d"},
|
||||||
|
@ -72,8 +72,8 @@
|
||||||
"arrayToObject": {"a": "b", "c": "d"},
|
"arrayToObject": {"a": "b", "c": "d"},
|
||||||
"arrayGrow": [1, 2, 3, 4, 5],
|
"arrayGrow": [1, 2, 3, 4, 5],
|
||||||
"arrayShrink": [1, 3],
|
"arrayShrink": [1, 3],
|
||||||
// "autoToArray": [1, 2, 3], // FIXME: doesn't work yet (misses expand button)
|
"autoToArray": [1, 2, 3],
|
||||||
// "ArrayToAuto": 123, // FIXME: doesn't work yet (throws error)
|
"arrayToAuto": 123,
|
||||||
"objectGrow": {"a": "b", "c": "ddd", "e": "f"},
|
"objectGrow": {"a": "b", "c": "ddd", "e": "f"},
|
||||||
"objectShrink": {"c": "d"},
|
"objectShrink": {"c": "d"},
|
||||||
"objectToArray": [1, 2, 3],
|
"objectToArray": [1, 2, 3],
|
||||||
|
|
Loading…
Reference in New Issue