我在一个页面上有两个dynatree对象实例。我让树从各种XML数据中填充。有一个onChange事件,它让树更改它们使用的数据。在更改期间,我所做的最后一件事是对数据进行排序。当我调用排序函数时,它对两个实例都运行,导致第一个实例排序不正确。我对这两种排序的代码是:
$("#rightList").dynatree("getRoot").sortChildren(compareNodesRight, true);它使用此函数作为比较。
var compareNodesLeft = function(a,b)
{
//Find the sequence tags for both a and b.
var aKey = a.data.key;
var bKey = b.data.key;
var aValue = $(GLOBAL_LEFT_XML).find("item[id ='" + aKey + "'] data sequence").text();
var bValue = $(GLOBAL_LEFT_XML).find("item[id ='" + bKey + "'] data sequence").text();
return aValue > bValue ? 1 : aValue < bValue ? -1 : 0;
} 另一个函数调用另一个排序,即
$("#rightList").dynatree("getRoot").sortChildren(compareNodesRight, true);它使用的函数与另一个函数几乎相同,只是它被称为
var compareNodesRight = function (a, b)
{
console.log("Comparing RIGHT");
//Find the sequence tags for both a and b.
var aKey = a.data.key;
var bKey = b.data.key;
var aValue = $(GLOBAL_RIGHT_XML).find("item[id ='" + aKey + "'] data sequence").text();
var bValue = $(GLOBAL_RIGHT_XML).find("item[id ='" + bKey + "'] data sequence").text();
return aValue > bValue ? 1 : aValue < bValue ? -1 : 0;
};任何关于.sortChildren函数的见解都会很棒。
发布于 2012-04-14 04:33:03
这只是一个缓存问题...
https://stackoverflow.com/questions/9485391
复制相似问题