Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Passing the event from the class to the object

I’m using http://wwwendt.de/tech/fancytree
I don’t understand how to bubble an event up into an object.

I have my class

class FTree2 {

    constructor(xparent) {
        this.xparent = xparent;
    }

    Init(params) {

        this.objtree = $(this.xparent).fancytree({
            extensions: ["dnd", "filter"],

            activate: function(event, data) {
                alert("activate");
            }
        });
    }

    addNode(title) {
        var tree = $.ui.fancytree.getTree(this.xparent);
        var parent = tree.getRootNode();

        var node = parent.addChildren({
            title: title,
            folder: false,
        });
    }
}

I use it this way:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  var ftree = new FTree2("#tree");
  ftree.Init();

  ftree.addNode("first");
  ftree.addNode("second");


  MyFunction() {
      alert ("node activated");
  }

   

How can I "connect" MyFunction to fancytree function "activate"?
Thanks.

>Solution :

Pass it as an argument:

    Init(callback) {

        this.objtree = $(this.xparent).fancytree({
            extensions: ["dnd", "filter"],

            activate: function(event, data) {
                callback()
            }
        });
    }
function MyFunction() {
  alert ("node activated");
}

var ftree = new FTree2("#tree");
ftree.Init(MyFunction);

ftree.addNode("first");
ftree.addNode("second");
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading