如何在jquery dynatree http://wwwendt.de/tech/dynatree/index.html中对所有子后续子节点进行排序?
使用此行$("#categoryTree").dynatree("getRoot").sortChildren(compare, false);
我能够对第一级节点进行排序,但内部的元素也需要排序。
var compare = function (a, b) {
a = a.data.title.toLowerCase();
b = b.data.title.toLowerCase();
return a > b ? 1 : a < b ? -1 : 0;
};
var tree = $("#categoryTree").dynatree({
checkbox: true,
selectMode: 3,
children: data,
onPostInit: function (isReloading, isError) {
$("#categoryTree").dynatree("getRoot").sortChildren(compare, false);
$(".dynatree-selected").each(function () {
var node = $.ui.dynatree.getNode(this);
node.visitParents(function (node) {
node.toggleExpand();
}, true);
});
$(".dynatree-partsel:not(.dynatree-selected)").each(function () {
var node = $.ui.dynatree.getNode(this);
node.visitParents(function (node) {
node.toggleExpand();
}, true);
});
}
});
答案 0 :(得分:0)
这对我有用
var root = $("#categoryTree").dynatree("getRoot");
for (var i = 0; i < root.getChildren().length; i++) {
root.getChildren()[i].sortChildren(compare, false);
}