Skip to content
This repository has been archived by the owner on Feb 5, 2025. It is now read-only.

Commit

Permalink
Fixed lazy-loading when calling expandNode()
Browse files Browse the repository at this point in the history
  • Loading branch information
skateman committed Sep 14, 2016
1 parent 05b9371 commit f22724f
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/js/bootstrap-treeview.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,19 +524,23 @@

// Lazy-load the child nodes if possible
if (typeof(this._options.lazyLoad) === 'function' && node.lazyLoad) {
// Show a different icon while loading the child nodes
node.$el.children('span.expand-icon')
.removeClass(this._options.expandIcon)
.addClass(this._options.loadingIcon);

var _this = this;
this._options.lazyLoad(node, function (nodes) {
// Adding the node will expand its parent automatically
_this.addNode(nodes, node);
});
this._lazyLoad(node);
} else {
this._setExpanded(node, !node.state.expanded, options);
}
};

Tree.prototype._lazyLoad = function (node) {
// Show a different icon while loading the child nodes
node.$el.children('span.expand-icon')
.removeClass(this._options.expandIcon)
.addClass(this._options.loadingIcon);

var _this = this;
this._options.lazyLoad(node, function (nodes) {
// Adding the node will expand its parent automatically
_this.addNode(nodes, node);
});
// Only the first expand should do a lazy-load
delete node.lazyLoad;
};
Expand Down Expand Up @@ -1528,6 +1532,11 @@
$.each(nodes, $.proxy(function (index, node) {
// Do not re-expand already expanded nodes
if (node.state.expanded) return;

if (typeof(this._options.lazyLoad) === 'function' && node.lazyLoad) {
this._lazyLoad(node);
}

this._setExpanded(node, true, options);
if (node.nodes) {
this._expandLevels(node.nodes, options.levels-1, options);
Expand Down

0 comments on commit f22724f

Please sign in to comment.