-
10 May 2012 10:12 AM #1
TreeStore removeAll() fails
TreeStore removeAll() fails
I've noticed some problems when I call removeAll() on a StoreTree item. It fails, because apparently the function removes the most inner children first. Then it checks the parent with hasChildNodes() which was a non-leaf item, but since it has removed all the children already, this function fails. hasChildNodes() is defined as follows:
After the children have been deleted, this.childNodes.length no longer exists.Code:hasChildNodes : function() { return !this.isLeaf() && this.childNodes.length > 0; }
I have worked around this issue with the following modification:
But the removeAll() function should either update the leaf value to true after deleting all the children of a non-leaf node or handle this in other fashion.Code:hasChildNodes : function() { return !this.isLeaf() && this.childNodes != null && this.childNodes.length > 0; }
Also I've realized that removeAll() doesn't handle the situation when it's called on an empty TreeStore.
Could I be doing something wrong or is this a bug?
-
15 May 2012 6:13 AM #2
Try using tree.removeAll() instead of store.removeAll()
Regards,
Scott.
-
15 May 2012 6:29 AM #3
Hi Scott,
I'm using it directly on the TreeStore. That's what's failing for me.
-
17 May 2012 4:50 AM #4
Action about state should be against the store. In Ext JS 4.1, I also see a bug with removeAll against the TreeStore. The root node is not deleted. So any other call to removeAll, like about "replacing" the data will fail, because the call to nodeInterface.destroy removed some expected state. Same logic was working fine in Ext JS 3.4.
The code of the library in TreeStore is:
Then in NodeInterface:Code:removeAll: function() { var root = this.getRootNode(); if (root) { root.destroy(true); } this.fireEvent('clear', this); }
Code:destroy : function(silent) { /* * Silent is to be used in a number of cases * 1) When setRoot is called. * 2) When destroy on the tree is called * 3) For destroying child nodes on a node */ var me = this, options = me.destroyOptions, nodes = me.childNodes, nLen = nodes.length, n; if (silent === true) { me.clear(true); for (n = 0; n < nLen; n++) { nodes[n].destroy(true); } me.childNodes = null; delete me.destroyOptions; me.callOverridden([options]); } else { me.destroyOptions = silent; // overridden method will be called, since remove will end up calling destroy(true); me.remove(true); }


Reply With Quote
