Pergunta

I have two instances of dynatree objects on a page. I have the trees populate from various XML data. There is an onChange event which has the trees change the data they are using. The last thing I do during the change is sort the data. When I call the sort function it runs for both of the instances causing the first one to be sorted incorrectly. My code for the two sorts is:

$("#rightList").dynatree("getRoot").sortChildren(compareNodesRight, true);

Which uses this function as the comparision.

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;
} 

The other function calls the other sort which is

$("#rightList").dynatree("getRoot").sortChildren(compareNodesRight, true);

It uses a function that is almost identical to the other except it is called

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;
};

Any insight about the .sortChildren function would be great.

Foi útil?

Solução

It was just a caching issue...

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top