$(function() { "use strict"; $.widget('custom.cwTreeView', { options: { width: '100%', height: 'auto', maxDepth: 3, delegateDataSource: function(data, alterObj) { // return promise }, onClickTreeItem: function(element, data) { }, }, _isLoading: false, _init: function() { this.selectedItem = null; }, _create: function() { this.main = $('
', { 'class': 'cw-widget-content' }); $(this.element).css( { width: this.options.width, height: this.options.height }); this.main.appendTo(this.element); this._loadData({ depth: 0, id: null, element: this.main }); }, reload: function(item) { this._reloadData(item); }, reset: function(data) { if (data.children != null) { data.children.remove(); } this._loadData(data); }, _reloadData: function(data) { if (data.children != null) { data.children.remove(); } this._loadData(data); }, _loadData: function(data) { var self = this; if (self._isLoading) return; var alterObj = { Id: 'Id', Name: 'Name', IsFunction: true }; var promise = this.options.delegateDataSource(data, alterObj); if (promise === null) { data.span.removeClass('cw-icon-arrow-right cw-icon-arrow-down'); return; } self._isLoading = true; promise.always(function() { self._isLoading = false; }); promise.done(function(array) { if (array === null || array.length === 0) { if (data.depth > 0) { data.span.removeClass('cw-icon-arrow-right cw-icon-arrow-down'); } return; } var ul = $('