/*
* Async Treeview 0.1 - Lazy-loading extension for Treeview
*
* http://bassistance.de/jquery-plugins/jquery-plugin-treeview/
*
* Copyright (c) 2007 Jörn Zaefferer
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
* Revision: $Id$
*
*/
;(function($) {
function load(settings, root, child, container) {
//rnUrl清除缓存
var rndUrl = settings.url + "?rnd=" + Math.round(Math.random()*10000);
$.getJSON(rndUrl , {root: root}, function(response) {
function createNode(parent) {
var current = $("<li/>").attr("id", this.id || "").html("<span>" + this.text + "</span>").appendTo(parent);
if (this.classes) {
current.children("span").addClass(this.classes);
}
if (this.expanded) {
current.addClass("open");
}
if (this.hasChildren || this.children && this.children.length) {
var branch = $("<ul/>").appendTo(current);
if (this.hasChildren) {
current.addClass("hasChildren");
createNode.call({
text:"placeholder",
id:"placeholder",
children:[]
}, branch);
}
if (this.children && this.children.length) {
$.each(this.children, createNode, [branch])
}
}
}
$.each(response, createNode, [child]);
$(container).treeview({add: child});
});
}
var proxied = $.fn.treeview;
$.fn.treeview = function(settings) {
if (!settings.url) {
return proxied.apply(this, arguments);
}
var container = this;
load(settings, "source", this, container);
var userToggle = settings.toggle;
return proxied.call(this, $.extend({}, settings, {
collapsed: true,
toggle: function() {
var $this = $(this);
if ($this.hasClass("hasChildren")) {
var childList = $this.removeClass("hasChildren").find("ul");
childList.empty();
load(settings, this.id, childList, container);
}
if (userToggle) {
userToggle.apply(this, arguments);
}
}
})).bind({
// modified by Timm Maass http://www.timm-maass.de/
// reload item by id, example:
// $('#treeid').treeview({reload:['nodeid']});
reload : function(event, myvar) {
var item = $(this).find("#"+myvar);
var childList = item.find("ul");
childList.empty();
load(settings, myvar[0], childList, container);
}
}
);
};
})(jQuery);
http://forum.jquery.com/topic/jquery-treeview-async-treeview-reload-branche
分享到:
相关推荐
实例082 从DataGridView控件拖放数据至TreeView控件 113 实例083 在DataGridView控件中实现合并单元格 116 实例084 在DataGridView控件中显示图片 118 实例085 为DataGridView控件实现复选功能 120 实例086 禁用...
实例082 从DataGridView控件拖放数据至TreeView控件 113 实例083 在DataGridView控件中实现合并单元格 116 实例084 在DataGridView控件中显示图片 118 实例085 为DataGridView控件实现复选功能 120 实例086 禁用...
实例082 从DataGridView控件拖放数据至TreeView控件 113 实例083 在DataGridView控件中实现合并单元格 116 实例084 在DataGridView控件中显示图片 118 实例085 为DataGridView控件实现复选功能 120 实例086 禁用...
实例082 从DataGridView控件拖放数据至TreeView控件 113 实例083 在DataGridView控件中实现合并单元格 116 实例084 在DataGridView控件中显示图片 118 实例085 为DataGridView控件实现复选功能 120 实例086 禁用...
54 <br>0075 用回溯法找出n个自然数中取r个数的全排列 55 <br>0076 约瑟夫环问题 56 <br>0077 猴子选大王 57 <br>0078 如何判断IP是否正确 57 <br>0079 如何将小写金额转换为大写金额 57...
15.4 局部页面缓存 15.4.1 VaryByControl 15.4.2 共享缓存控件 15.5 总结 第16章 主题和母版页 16.1 层叠样式表 16.1.1 创建样式表 16.1.2 应用样式表规则 16.2 主题 16.2.1 主题文件夹和外观 ...
实例197 通过子窗体刷新父窗体 264 实例198 拖动无边框窗体 265 实例199 禁用窗口上的关闭按钮 267 实例200 向窗体中拖放图片并显示 268 实例201 使应用程序在进程中消失 269 9.2 其他窗体技术 270 实例202 在关闭...