Skip to content

Commit c52e79a

Browse files
committed
data field editor
1 parent 182dd9b commit c52e79a

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

src/data-field-editor.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export default {
8181
console.log(this.selectedType, this.value);
8282
const value = this.converters[this.selectedType](this.value);
8383
const newKv = Object.assign({}, this.kv);
84-
newKv.name = this.name.trim();
84+
newKv.newName = this.name.trim();
8585
newKv.dataType = this.selectedType;
8686
newKv.value = value;
8787

src/json-vuer.vue

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import JsonNode from "./node";
2929
import FieldEditor from "./data-field-editor";
3030
import Modal from "./modal";
3131
import Dispatcher from "./utils/dispatcher";
32+
import { deepClone } from "./utils";
3233
3334
export default {
3435
name: "JsonVuer",
@@ -164,7 +165,7 @@ export default {
164165
this.$set(this.src, path[0], this.src[path[0]]);
165166
} else {
166167
delete obj[data.name];
167-
this.$set(this.src, path[0], Object.assign({}, this.src[path[0]]));
168+
this.$set(this.src, path[0], deepClone(this.src[path[0]]));
168169
}
169170
},
170171
onFieldChange(data) {
@@ -187,8 +188,11 @@ export default {
187188
obj.splice(data.name, 1, data.value);
188189
this.$set(this.src, path[0], this.src[path[0]]);
189190
} else {
190-
obj[data.name] = data.value;
191-
this.$set(this.src, path[0], Object.assign({}, this.src[path[0]]));
191+
if (data.name !== data.newName) {
192+
delete obj[data.name];
193+
}
194+
obj[data.newName] = data.value;
195+
this.$set(this.src, path[0], deepClone(this.src[path[0]]));
192196
}
193197
},
194198
},

src/utils/index.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
export function deepClone(obj) {
3+
let cloned;
4+
if (typeof obj !== 'object' || !obj) {
5+
cloned = obj;
6+
return cloned;
7+
}
8+
9+
10+
if (obj instanceof Array) {
11+
cloned = [];
12+
for (let i of obj) {
13+
cloned.push(deepClone(i))
14+
}
15+
} else {
16+
cloned = {};
17+
18+
const keys = Object.keys(obj);
19+
20+
for (let key of keys) {
21+
cloned[key] = deepClone(obj[key])
22+
}
23+
}
24+
25+
return cloned;
26+
27+
}

0 commit comments

Comments
 (0)