daison
July 25, 2017, 10:19am
#1
I have an GoJS(1.7.1) memo editor.Using this editor I can create memo which contains text, image and freehand drawing.
When clicked save button, I want to save memo and clear editor.
I am using following code to clear diagram.model
$scope.model.startTransaction("clearMemo");
$scope.model.nodeDataArray = [];
$scope.model.commitTransaction("clearMemo");
But the content of the editor is not cleared.It will clear only when I click on the editor.
I am also tried
diagram.requestUpdate();
Still it is not cleared on save button click.
Could you please suggest any idea/trick to clear my editor?
walter
July 25, 2017, 10:41am
#2
If you are using GraphLinksModel your code won’t remove any links.
The easiest way to clear a diagram is to replace the Diagram.model with an empty one. No transaction is needed or permitted.
Or call Diagram.clear .
daison
July 25, 2017, 12:41pm
#3
Diagram.clear() is working fine.Thanks
One more issue related to nodeDataArray update
$scope.model.startTransaction(“addMemos”);
$scope.model.nodeDataArray = nodeArray;
$scope.model.commitTransaction(“addMemos”);
diagram.requestUpdate()
diagram is refreshed only when click on diagram.
walter
July 25, 2017, 1:52pm
#4
I just tried executing:
myDiagram.model.startTransaction();
myDiagram.model.nodeDataArray = [];
myDiagram.model.linkDataArray = [];
myDiagram.model.commitTransaction("cleared");
as well as:
myDiagram.model.startTransaction();
myDiagram.model.nodeDataArray = [{ key: 1, text: "Start" }, { key: 2, text: "End" }];
myDiagram.model.linkDataArray = [{ from: 1, to: 2 }];
myDiagram.model.commitTransaction("cleared");
from an HTML button (i.e. not while doing something in the diagram), and it updated correctly, immediately, without any interaction on my part as a user.