Fix collapsing panel

pull/1/head
ioedeveloper 5 years ago
parent bffc543157
commit 5898882082
  1. 9
      src/app/ui/TreeView.js

@ -45,6 +45,7 @@ class TreeView {
this.extractData = opts.extractData || this.extractDataDefault this.extractData = opts.extractData || this.extractDataDefault
this.formatSelf = opts.formatSelf || this.formatSelfDefault this.formatSelf = opts.formatSelf || this.formatSelfDefault
this.view = null this.view = null
this.expandPath = []
} }
render (json, expand) { render (json, expand) {
@ -86,14 +87,20 @@ class TreeView {
${caret} ${caret}
<span>${self.formatSelf(key, data, li)}</span> <span>${self.formatSelf(key, data, li)}</span>
</div>` </div>`
const expanded = self.expandPath.includes(keyPath)
li.appendChild(label) li.appendChild(label)
if (data.children) { if (data.children) {
var list = yo`<ul key=${keyPath} data-id="treeViewUlList${keyPath}" class=${css.ul_tv}>${children}</ul>` var list = yo`<ul key=${keyPath} data-id="treeViewUlList${keyPath}" class=${css.ul_tv}>${children}</ul>`
list.style.display = 'none' list.style.display = expanded ? 'block' : 'none'
caret.className = list.style.display === 'none' ? `fas fa-caret-right caret ${css.caret_tv}` : `fas fa-caret-down caret ${css.caret_tv}` caret.className = list.style.display === 'none' ? `fas fa-caret-right caret ${css.caret_tv}` : `fas fa-caret-down caret ${css.caret_tv}`
caret.setAttribute('data-id', `treeViewToggle${keyPath}`) caret.setAttribute('data-id', `treeViewToggle${keyPath}`)
label.onclick = function () { label.onclick = function () {
self.expand(keyPath) self.expand(keyPath)
if (self.isExpanded(keyPath)) {
if (!self.expandPath.includes(keyPath)) self.expandPath.push(keyPath)
} else {
self.expandPath = self.expandPath.filter(path => path != keyPath)
}
} }
label.oncontextmenu = function (event) { label.oncontextmenu = function (event) {
self.event.trigger('nodeRightClick', [keyPath, data, label, event]) self.event.trigger('nodeRightClick', [keyPath, data, label, event])

Loading…
Cancel
Save