From 31f5e72b2ba3e52a8e5efc2190b5d4aa97de87e2 Mon Sep 17 00:00:00 2001 From: salexdv Date: Thu, 25 Aug 2022 15:04:10 +0300 Subject: [PATCH] tree dispose --- src/tree/tree.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/tree/tree.js b/src/tree/tree.js index be241bb..71310b3 100644 --- a/src/tree/tree.js +++ b/src/tree/tree.js @@ -1,17 +1,19 @@ class Treeview { constructor(treeviewId, editor, imageBase) { + let self = this; this.treeviewId = treeviewId; this.editor = editor; this.selected = null; this.imageBase = imageBase; - document.querySelector(this.treeviewId).addEventListener("click", (event) => { - this.on("click", event); - }); - document.querySelector(this.treeviewId) + this.clickListener = function(event) { + self.on("click", event); + } + document.querySelector(this.treeviewId).addEventListener("click", this.clickListener); }; on(eventName, eventData) { - switch (eventName) { + switch (eventName) { case "click": { + console.log(eventData); if (eventData.target.tagName == 'A') { eventData.preventDefault(); let element = eventData.target; @@ -106,6 +108,7 @@ class Treeview { document.getElementById(id).click(); }; dispose() { + document.querySelector(this.treeviewId).removeEventListener("click", this.clickListener); document.querySelector(this.treeviewId).innerHTML = ''; }; } \ No newline at end of file