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:
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.
CodePudding user response:
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");