draw2d icon indicating copy to clipboard operation
draw2d copied to clipboard

Children of nodes are not serialized to JSON

Open rudolphi opened this issue 3 years ago • 0 comments

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

}

rudolphi avatar May 17 '21 08:05 rudolphi