From 3da44a87ce435a09ef81339a8044a52769311ce9 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 23 Jan 2017 12:58:00 +0100 Subject: [PATCH] change keyPath name and type --- src/ui/TreeView.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ui/TreeView.js b/src/ui/TreeView.js index fe05aa580b..71269f15f3 100644 --- a/src/ui/TreeView.js +++ b/src/ui/TreeView.js @@ -16,7 +16,7 @@ class TreeView { this.cssLabel = ui.formatCss(opts.css || {}, style.label) this.cssUl = ui.formatCss(opts.css || {}, style.cssUl) this.cssLi = ui.formatCss(opts.css || {}, style.cssLi) - this.keyPaths = {} + this.nodeIsExpanded = {} } render (json) { @@ -36,7 +36,7 @@ class TreeView { renderObject (item, parent, key, expand, keyPath) { var data = this.extractData(item, parent, key) var children = (data.children || []).map((child, index) => { - return this.renderObject(child.value, data, child.key, expand, keyPath + '_' + child.key) + return this.renderObject(child.value, data, child.key, expand, keyPath + ',' + child.key) }) return this.formatData(key, data, children, expand, keyPath) } @@ -53,14 +53,14 @@ class TreeView { var renderedChildren = '' if (children.length) { renderedChildren = yo`` - renderedChildren.style.display = this.keyPaths[keyPath] ? this.keyPaths[keyPath] : expand ? 'block' : 'none' + renderedChildren.style.display = this.nodeIsExpanded[keyPath] !== undefined ? (this.nodeIsExpanded[keyPath] ? 'block' : 'none') : (expand ? 'block' : 'none') label.firstElementChild.className = renderedChildren.style.display === 'none' ? 'fa fa-caret-right' : 'fa fa-caret-down' var self = this label.onclick = function () { this.firstElementChild.className = this.firstElementChild.className === 'fa fa-caret-right' ? 'fa fa-caret-down' : 'fa fa-caret-right' var list = this.parentElement.querySelector('ul') list.style.display = list.style.display === 'none' ? 'block' : 'none' - self.keyPaths[keyPath] = list.style.display + self.nodeIsExpanded[keyPath] = list.style.display === 'block' } } return yo`
  • ${label}${renderedChildren}
  • `