mbraak / jqTree

Tree widget for jQuery
https://mbraak.github.io/jqTree/
Apache License 2.0
1.02k stars 177 forks source link

loadData bug, not giving the node back #18

Closed jivanrij closed 12 years ago

jivanrij commented 12 years ago

I think i found a bug, ik wanted to use loadData, it didn't work because the node i got back from getNodeById was null. After a bit of searching i saw that the node_id & node.id in the getNodeById function are beeing compared with ===, instead of ==.

JqueryWidget.prototype.getNodeById = function(node_id) {
  var result;
  result = null;
  this.tree.iterate(function(node) {
    if (node.id === node_id) {
      result = node;
      return false;
    } else {
      return true;
    }
  });
  return result;
};

jqTree is awesome btw, i love it :)

mbraak commented 12 years ago

This can be a problem if the node_id parameter is a string and the node ids are integers.

You can fix this by using parseInt:

var node = $('tree1').getNodeById(parseInt('30'));

Anyway, I do agree that using '==' would be better in this case. I can't change that at this moment because jqTree is written in CofeeScript, and CoffeeScript does not allow '==' (see http://coffeescript.org/#operators).

jivanrij commented 12 years ago

Oke, sounds logic, i'll do that.

mbraak commented 12 years ago

Changed in the dev branch: the getNodeById comparison is now less strict. It uses the javascript '=='.

jivanrij commented 12 years ago

thanks, i'm using 1.3.1 now, works fine :)