var DataSourceTree = function (options) {
this.url = options.url;
}
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({
url: this.url,
data: 'id=' + param,
type: 'POST',
dataType: 'json',
success: function (response) {
callback(response)
},
error: function (response) {
console.log(response);
}
})
}
}
};
$('#tree2').admin_tree({
dataSource: new DataSourceTree({ url: '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
});
我从AccountTree.ashx恢复了这个JSON数据 {\“data \”:[{\“id \”:1,\“name \”:\“label 1 \”,\“type \”:\“folder \”,\“additionalParameters \”:{\ “ID \”:1,\ “孩子\”:真实的,\ “itemSelected \”:虚假,\ “名称\”:\ “测试\”,\ “类型\”:\ “项\”}}]}
我知道回调(响应)中有问题
http://i.stack.imgur.com/6DEtr.png
必须是label1 - &gt;项目
答案 0 :(得分:0)
您的数据源功能似乎没有更改您从中获取JSON的URL。
当打开文件夹节点时,它使用数据源提供的任何JSON。使用attr
键和事件opened.fu.tree
为您的节点提供数据属性,然后通知/操纵您的数据源并告诉它要加载哪个URL以及JSON。