draw2d
draw2d copied to clipboard
Children of nodes are not serialized to JSON
Proposed fix in draw2d/src/shape/node/Node.js: getPersistentAttributes: function () { let memento = this._super()
// ...
memento.children = []
this.children.each(function (i, child) { // getChildren() misses the locator
memento.children.push(extend(child.figure.getPersistentAttributes(), {
// no child.figure.getName()
child: child.figure.NAME,
locator: child.locator.NAME,
locatorAttr: child.locator.attr()
}))
})
return memento
},
// ... setPersistentAttributes: function (memento) { this._super(memento)
// ...
// remove all children created in the init method
//
this.resetChildren()
// and restore all children of the JSON document instead.
//
memento.children.forEach((e) => {
let locator = eval("new " + e.locator + "()")
if(e.locatorAttr) {
locator.attr(e.locatorAttr)
}
let child = eval("new " + e.child + "()")
child.setPersistentAttributes(e)
this.add(child, locator)
})
return this
}