-
12 Feb 2013 7:53 AM #1
NodeInterface.eachChild Scope does not iterate over children
NodeInterface.eachChild Scope does not iterate over children
Sorry if this is a dup. Couldn't find it in the Ext 4 list.
NodeInterface.eachChild still has problems with scoping even after FIXED-1166. According to documentation:
The scope in the callback still defaults to the parent node and not the each child. Code to reproduce:scope : Object (optional)
The scope (this reference) in which the function is executed. Defaults to the current Node in iteration.
Callback args default to passing in the current node in the iteration, but if I want to pass any of my own args into the callback, I lose the current node. Coupled with the scoping bug, this means I can't pass any vars into the callback without having to manually iterate through the children.Code:var store = new Ext.data.TreeStore({ root : { id: 0, name: 'root', children: [ { id: 1, name: 'child 1' }, { id: 2, name: 'child 2' }, { id: 3, name: 'child 3' } ] } }); var myCallback = function callbackFunc ( node ) { console.log( "this", this.getId() ); // always reports id 0 console.log( "node", node.getId() ); // correctly iterates through child id } store.getRootNode().eachChild( myCallback );
Based on 4.1.3 source code, the following will fix the problem (offending line commented out and the fix immediately below it).
Code:eachChild : function(fn, scope, args) { var childNodes = this.childNodes, length = childNodes.length, i; for (i = 0; i < length; i++) { // if (fn.apply(scope || this, args || [childNodes[i]]) === false) { if (fn.apply(scope || childNodes[i], args || [childNodes[i]]) === false) { break; } } },
-
12 Feb 2013 8:06 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,127
- Vote Rating
- 453
Thanks for the report! I have opened a bug in our bug tracker.
Also, the link you specified was for Ext JS 3 so that fix has no bearing on this bug, this is just a regression between major versions.
-
12 Feb 2013 8:08 AM #3
Cool beans. Linked the Ext3 issue in case you guys wanted to backport ando/or have an upstream from 3 to 4.
You found a bug! We've classified it as
EXTJSIV-8604
.
We encourage you to continue the discussion and to find an acceptable workaround while we work on a permanent fix.


Reply With Quote