made replaceKey recursive function
This commit is contained in:
@ -6,6 +6,19 @@ export abstract class XmlComponent {
|
|||||||
this.root = new Array<XmlComponent>();
|
this.root = new Array<XmlComponent>();
|
||||||
this.rootKey = rootKey;
|
this.rootKey = rootKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
replaceKey() {
|
||||||
|
console.log(this.rootKey);
|
||||||
|
console.log(this.root);
|
||||||
|
if (this.root !== undefined) {
|
||||||
|
this.root.forEach(root => {
|
||||||
|
root.replaceKey();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
this[this.rootKey] = this.root;
|
||||||
|
//Object(this)[this.rootKey]
|
||||||
|
delete this.root;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AttributesProperties {
|
interface AttributesProperties {
|
||||||
|
@ -1,24 +1,33 @@
|
|||||||
import * as _ from "lodash";
|
import * as _ from "lodash";
|
||||||
|
import {XmlComponent} from "../docx/xml-components";
|
||||||
|
|
||||||
export class Formatter {
|
export class Formatter {
|
||||||
|
|
||||||
format(input: any): Object {
|
format(input: any): Object {
|
||||||
|
this.replaceKeys(input);
|
||||||
|
var newJson = this.clense(input);
|
||||||
|
|
||||||
|
return newJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
private replaceKeys(input: XmlComponent): Object {
|
||||||
|
input.replaceKey();
|
||||||
this.deepTraverseJson(input, (parent, value, key) => {
|
this.deepTraverseJson(input, (parent, value, key) => {
|
||||||
if (isNaN(key) && key !== "rootKey") {
|
/*if (isNaN(key) && key !== "rootKey") {
|
||||||
var newKey = parent.rootKey;
|
var newKey = parent.rootKey;
|
||||||
console.log(key);
|
console.log(key);
|
||||||
if (newKey !== key) {
|
if (newKey) {
|
||||||
parent[newKey] = parent[key];
|
parent[newKey] = parent[key];
|
||||||
delete parent[key];
|
delete parent[key];
|
||||||
} else {
|
} else {
|
||||||
//console.error("Key is not in dictionary:" + key);
|
//console.error("Key is not in dictionary:" + key);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
//console.log(value);
|
||||||
|
//parent.replaceKey();
|
||||||
});
|
});
|
||||||
|
|
||||||
var newJson = this.clense(input);
|
return input;
|
||||||
|
|
||||||
return newJson;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private clense(input: any): Object {
|
private clense(input: any): Object {
|
||||||
|
Reference in New Issue
Block a user