this in that context is not well defined and you shouldn’t be using it. You are not defining something on the Diagram’s prototype so this is just whatever it was in the outside scope, or potentially nothing.
You could try making a closure:
var self = this; // if you are sure of what 'this' is here
myDiagram.addDiagramListener("ExternalObjectsDropped", function(){
self.saveJson(myDiagram.model.toJson());
console.log("network : ", myDiagram.model.toJson());
});
I have found a solution if someone got the same problem.
For some reason this is undefined in a GoJs eventListener. so in the beggining of my renderCanvas
It might be easier to replace the use of function() { ... } with () => { ... }. That’s JavaScript for you.
No GoJS event listeners or functional properties ever have this bound when called. That’s because when we designed the API we knew that some day there would be “arrow functions”. Although at the time I don’t think we even knew about the syntax or that they would be called “arrow functions”. It’s been too long for me to remember…
The only functions that have this bound are methods of classes, some of which may be overridden.