Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic links.Add and nodes.Add methods don't appear to work (Read 2336 times)
Megan1717
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 39
Joined: Jun 20th, 2016
links.Add and nodes.Add methods don't appear to work
May 21st, 2020 at 11:22pm
Print Post  
Hello,

I am having trouble getting the following methods to work server side:

diagram.Links.Add()
diagram.Nodes.Add()

Here is my code:
Code (Java)
Select All
Diagram d = new Diagram();
DiagramLink newLink = CreateNewLink(d); //sets various link properties
d.Links.Add(newLink);
 



Code (Java)
Select All
Diagram d = new Diagram();
DiagramNode newNode = CreateNewNode(d); //sets various node properties
d.Nodes.Add(newNode);
 



This happens for new diagrams as well as existing ones I deserialize from Json and then try to modify by adding links or nodes.

Code (Java)
Select All
public ActionResult ModifyDiagram(string diagramJson, string linkJson)
DiagramView view = DiagramView.FromJson(diagramJson);
  jsSerializer.RegisterConverters(new JavaScriptConverter[] { new DiagramLinkConverter(view) });
 DiagramLink link = jsSerializer.Deserialize<DiagramLink>(linkJson);
view.Diagram.Links.Add(link);
 



Thanks.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: links.Add and nodes.Add methods don't appear to work
Reply #1 - May 22nd, 2020 at 6:58am
Print Post  
Hi,

We aren't sure what's the question exactly. If you need to get newly created items back on client side, then return the modified diagram view as result -

Code
Select All
public ActionResult ModifyDiagram ...
{...
return Json(new { success = DiagramView.ToJson(view) });
}

 $.ajax({
..
         success: function (result)
                {
                    diagram.fromJson(result.success);
 



Something like that's shown in ClientEvents sample project.

Also that last code snippet of yours looks like it will add same link for a second time if linkJson is already included in diagramJson.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Megan1717
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 39
Joined: Jun 20th, 2016
Re: links.Add and nodes.Add methods don't appear to work
Reply #2 - May 22nd, 2020 at 5:08pm
Print Post  
Hello,

I will try to clarify what my question is:

If I create a DiagramLink and try to add it using (diagram.Links.Add(newLink), the link is not added to the diagram's link collection. The count remains the same.

The same thing happens if I create a new node and try to add it to the diagram's node collection (diagram.Nodes.Add(newNode). The new node is not added.

Do you know of any reason why the Add methods would not work that I can use to troubleshoot this issue?

In my last code snippet, yes I know that am re-adding the same link. What I actually do is remove that link, modify it (since that link has no Id or Tag or other properties I need), and then try to re-add it to the diagram.

Here is the full code:

Code (Java)
Select All
public ActionResult ModifyDiagram(string diagramJson, string linkJson)
DiagramView view = DiagramView.FromJson(diagramJson);
  jsSerializer.RegisterConverters(new JavaScriptConverter[] { new DiagramLinkConverter(view) });
 DiagramLink link = jsSerializer.Deserialize<DiagramLink>(linkJson);
Diagram currentDiagram = view.Diagram;
currentDiagram.Links.Remove(link);
link = AddNewPropertiesToLink(link);
//this does not work!
currentDiagram.Links.Add(link);
 



My point is that the add method doesn't work, even if I am trying to add the link to a different diagram instance, because I have tried that, too. If you pretend I am adding a brand new link instead of the deserialized one, the result is the same: the link is NOT added to the diagram.

Why might cause the Add methods for links and nodes to fail?

Thanks.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: links.Add and nodes.Add methods don't appear to work
Reply #3 - May 26th, 2020 at 8:24am
Print Post  
We can't see any way for Nodes.Add to fail, please attach a test project reproducing it. Links.Add might not work if link's Origin and Destination are in a different Diagram.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint