google-code-export / dynatree

Automatically exported from code.google.com/p/dynatree
1 stars 0 forks source link

DynaTreeNode.remove throws an exception if the node isn't rendered #453

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
To reproduce:
1. Collapse a parent node
2. Call 'remove' for any child node and insert the same node again
3. Repeat step 2
'remove' method throws an error. In Chrome the error is:

Error: An attempt was made to reference a Node in a context where it does not 
exist.
at Object.DynaTreeNode.removeChild 
(http://dynatree.googlecode.com/svn/trunk/src/jquery.dynatree.js:1471:12)

In other browsers the error can be different.

jsFiddle: http://jsfiddle.net/tNcEJ/11/

Problem code - removeChild method, line 1437:
        if(this.ul){
//          $("li", $(this.ul)).remove(); // issue 399
            this.ul.removeChild(tn.li); // issue 402
        }
Replace with:
        if(this.ul && tn.li){
            this.ul.removeChild(tn.li); // issue 402
        }

I suppose you need to do the same thing in removeChildren method to fix issue 
231. At least move $("li", $(this.ul)).remove() out of the 'for' cycle, no need 
to remove all li nodes at each iteration.

Dynatree version: 1.2.4

Original issue reported on code.google.com by alkol...@gmail.com on 6 Sep 2013 at 11:16

GoogleCodeExporter commented 9 years ago

Original comment by moo...@wwwendt.de on 6 Sep 2013 at 1:49

GoogleCodeExporter commented 9 years ago
This issue was updated by revision r677.

Original comment by moo...@wwwendt.de on 8 Sep 2013 at 6:46

GoogleCodeExporter commented 9 years ago
could you please verify?

Original comment by moo...@wwwendt.de on 8 Sep 2013 at 6:46

GoogleCodeExporter commented 9 years ago
Works great, thanks! Please excuse me for a long delay.
What about the same fix in removeChildren method?

Original comment by alkol...@gmail.com on 25 Sep 2013 at 9:47

GoogleCodeExporter commented 9 years ago

Original comment by moo...@wwwendt.de on 3 Oct 2013 at 7:38

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r682.

Original comment by moo...@wwwendt.de on 6 Oct 2013 at 3:01