Hi
I have multiple link templates in one diagram.
how to change a link category for particular link at certain logic point.
and link should take effect (refreshing) immediately.
trying to use model.setCategoryForLinkData but it is warn me as unexist method. I am using go.js version 1.8.31.
If your Diagram.model is an instance of GraphLinksModel, that call should be correct. However the type of Diagram.model is just Model, which does not have that method defined, so if you care, you should cast this.diagram.model to a GraphLinksModel.
But in any case you should be executing that statement within a transaction. Are you conducting a transaction at that time?
OK, so the model is an instance of GraphLinksModel, so the call does not result in an error, but it does not have any effect either. I do not understand about a warning – what was that?
So you need to debug this. Are you using the go-debug.js library?
What is the value of linkData? And what is the value of linkData.category, both before and after the call?
Is the value of myDiagram.linkTemplateMap.get("subRedLink") a different link template than the template named by the previous category name?
That’s not a run-time warning, but an edit-time message from the language extension system pointing out that the Model class, the type of the Diagram.model property, does not support that method. But that has no effect on the run-time behavior, so you can ignore it.
No “category” property means it uses the default link template. Do you have a different link template named “subRedLink” in the Diagram.linkTemplateMap?
Ahh, so you’re not just changing the category, you’re also changing the class. Generally, when making such changes, you want to replace the link rather than just changing the category. I’m surprised there wasn’t a warning message that came up when you tried running this, I was given one. This way all the necessary functions will run using the new Link subclass.
I don’t know that the code is TypeScript, so that might not work.
The idea is that we cannot change the class of an existing GraphObject, but you can replace it with an instance of what you want. You definitely should have gotten a message about it in the console, even if you were using go.js rather than the usual go-debug.js when debugging.