From ad368fb8196445e6565b10a78e92e550f1a590d8 Mon Sep 17 00:00:00 2001 From: rolux Date: Sun, 17 Jun 2012 19:12:23 +0200 Subject: [PATCH] allow for updating a treelist's data option --- source/Ox.UI/js/List/TreeList.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/source/Ox.UI/js/List/TreeList.js b/source/Ox.UI/js/List/TreeList.js index 4c8c1f9c..a72abc52 100644 --- a/source/Ox.UI/js/List/TreeList.js +++ b/source/Ox.UI/js/List/TreeList.js @@ -34,7 +34,8 @@ Ox.TreeList = function(options, self) { .options(options || {}) .update({ data: function() { - // ... + self.options.items = getItems(); + self.$list.options({items: parseItems()}); }, selected: function() { //self.$list.options({selected: self.options.selected}); @@ -47,10 +48,7 @@ Ox.TreeList = function(options, self) { }); if (self.options.data) { - self.options.items = []; - Ox.sort(Object.keys(self.options.data)).forEach(function(key) { - self.options.items.push(parseData(key, self.options.data[key])); - }); + self.options.items = getItems(); } that.setElement( @@ -155,6 +153,14 @@ Ox.TreeList = function(options, self) { return ret; } + function getItems() { + var items = []; + Ox.sort(Object.keys(self.options.data)).forEach(function(key) { + items.push(parseData(key, self.options.data[key])); + }); + return items; + } + function getParent(id, items) { var ret; Ox.forEach(items, function(item) { @@ -207,7 +213,7 @@ Ox.TreeList = function(options, self) { level: level }, item, item.items ? { - items: !!item.expanded + items: item.expanded ? parseItems(item.items, level + 1) : [] }