var DataSourceTree = function (options) {
this.source = options.source;
}
DataSourceTree.prototype = {
data: function (options, callback) {
var self = this;
var $data = null;
var param = null
if (!("name" in options) && !("type" in options)) {
param = 0; //load the first level
} else if ("type" in options && options.type == "folder") {
if ("additionalParameters" in options && "children" in options.additionalParameters) {
param = options.additionalParameters["id"];
}
}
if (param != null) {
$.ajax({
source: this.source,
data: 'id=' + param,
type: 'POST',
dataType: 'json',
success: function (response) {
callback(response)
},
error: function (response) {
console.log(response);
}
})
}
}
};
$('#tree2').admin_tree({
dataSource: new DataSourceTree({ source: 'AccountTree.ashx' }),
loadingHTML: '<div class="tree-loading"><i class="fa fa-spinner fa-2x fa-spin"></i></div>',
'open-icon': 'fa-folder-open',
'close-icon': 'fa-folder',
'selectable': false,
'multiSelect': false,
'selected-icon': null,
'unselected-icon': null
});
this JSON data i revived from AccountTree.ashx {\"data\":[{\"id\":1,\"name\":\"label 1\",\"type\":\"folder\",\"additionalParameters\":{\"id\":1,\"children\":true,\"itemSelected\":false,\"name\":\"test\",\"type\":\"item\"}}]}
i know there is a problem in the callback(response)
https://i.sstatic.net/6DEtr.png
must be label1 --> item