Do not replace a Diagram.model while a transaction is in progress

hello,thanks for your answer,however I meet a new problem,could you help me solve it? the question is that "Do not replace a Diagram.model while a transation is in progress."when I want to creat a new flow chart,Looking forward to your reply. Thank you very much.

The error message is warning you that there is a transaction ongoing when you replace the value of Diagram.model.

That is because the UndoManager is associated with the Model, so replacing the model effectively replaces the undo manager, thereby losing whatever recorded state that the UndoManager has.

Why would you want to make that connection?Can I break the connection when I don’t need it.If I frequently open the page and close the page, I will report this error. Moreover, it is very strange that the method of go.model.fromjson cannot be executed sometimes, and it will report an error.Looking forward to your reply

The question really is: why do you have a transaction ongoing when you replace the Diagram.model? Transactions are supposed to be relatively short operations bounding a group of logically related changes to the diagram and/or model.

Replacing a diagram’s model is what you do when you want to load a new “document”. Just create and initialize the new Model and after it’s all initialized, you can set Diagram.model to exchange the old with the new.

Yes, changing the Diagram.model property is technically a change to a Diagram, but it’s a special case.

Hello, I’m initialized inside the body onload = operation “init ()”, I can open my page, if I am not in the body for initialization operation, I have to open a page, the second cannot open the page, create and initialize the new Model of how to implement, how to open the page over and over again, a second complains that div id is invalid, because has been associated with the corresponding diagram?Looking forward to your reply. Thank you very much

The natural and most common way of showing diagrams is to create the Diagram only once for a particular HTMLDivElement. Whenever you want to show a diagram, get a model and set Diagram.model.

This is what I use, but there was a problem, that is when I just finished editing a flow chart, to see other flow diagram, shown in the area is always I just edit flow diagram, not I want to see the flow chart, excuse me this how to deal with, I am using method is to go. Model. fromJson, but this method in the program if the call will perform it, could you tell me how to solve, this to look forward to your reply.

Take a look at the Local View sample, Local View. Whenever the user selects a new node in either diagram, the bottom diagram’s model is replaced with a new model showing only those nodes and links that are connected with the selected node.

Look at the implementation of showLocalOnFullClick. Ignore the code that is modifying the myFullDiagram, which is the top diagram. Most of that function constructs a new TreeModel and then assigns it to myLocalDiagram.model.

This sample does not put out any warnings about there being changes ongoing in the Diagram or the Model at the time you replace the Diagram.model. That is why I believe in your app you must be doing something to change the Diagram before you replace its model.

A post was split to a new topic: Problems with click events

You’re right. What I want to know is can’t you do something else when you replace the chart?My actual operation is like this, I carried out in a chart on delete attachment or module operation, but I didn’t save, and then return to the home page click again to enter the page to show other data, is stuck, unable to display the icon but I want to see I just edit chart, how to deal with, please?
Looking forward to your reply.

Why would you want to make changes to the old diagram when you intend to replace everything anyway with a new model/diagram?

Hello, may I ask how to use your company’s go.js to draw the flowchart? I want to show different flowchart on one page.Alternating between the data is not affected each other, I have seen in official website Model | GoJS API there are toJson and fromJson two ways to store and retrieve data, but I failed to correct when I was in his attempt to replace the flow diagram, is this why?

Yes, that is correct – to show a different diagram just create a new Model somehow and replace the existing Diagram.model. You can create the model either by calling Model.fromJson on a string that was written out by Model.toJson, or by creating and initializing a model programmatically.

but when I use this method,it’s failing,I have got data ,but i can not show data by this method,could you solve my problem?thank you.