0

Hi all I am working in JS plumb library for making connections.I am stuck at one point and need help from experts. Here is my scenario.

I have many connections and what I want is that when I click on one connection a certain label appears on it to show that it is selected.When I click one some other connection previously clicked connection disappears and new connection get selected.

What I have done so far is that

    jsPlumbInst.bind('click', function(c) {
         c.showOverlay('selected');
         var previously_active = jsPlumbInst.getConnections({scope:"active"});//this function not returning me values
         if(previously_active.length != 0) {
               /*So never go in this statement*/
               previously_active[0].hideOverlay('selected');
               previously_active.scope("jsPlumb_DefaultScope");  
          }
     c.scope = "active"; 
   });

Here the problem is that my connection scope is set to "active"

jsPlumbInst.getConnections({scope:"active"}) is not returning anything.

So can any one kindly guide me that whether I am doing right? Or is there any other way to achieve this?

A_user
  • 2,087
  • 6
  • 25
  • 33

1 Answers1

2

var sourcecon = jsPlumb.getConnections({source: e}) ; for(i=0; i<sourcecon.length; i++) { var target = getName(sourcecon[i].targetId) ; var source = getName(sourcecon[i].sourceId) ; removefrommatrix(source, target,sourcecon[i].sourceId,sourcecon[i].targetId) ; } This is code snippet which I am using. It works fine. Your code looks fine except just one difference that you have used jsPlumbInst rather than jsPlumb. I guess that could be the problem. For me its like static class in Java.Not sure about that. But try and see if it could help you.Seems like I am almost a year late in replying. All the best :-)

webcoder
  • 311
  • 1
  • 8
  • hi, am interested in your answer but i did not understand what is the 'e' in jsPlumb.getConnections({source: e}) ? is it the id of the source or the javascript varable that is the source ? – Tourki Dec 04 '13 at 22:24
  • @YAT I don't know for sure, but it looks like it's the variable for the string that contains the source ID. I say so because this manual suggests that the argument needs to be a string and it's not a string here. http://jsplumbtoolkit.com/doc/querying – thefourtheye Dec 10 '13 at 02:49
  • 1
    @thefourtheye : thanks for answering, actually i did some search since and found that it's the Id attribute of the html element that is the source, same thing with the target – Tourki Dec 10 '13 at 08:50