1. #1
    Sencha - Community Support Team mystix's Avatar
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    6,236
    Vote Rating
    5
    mystix will become famous soon enough

      0  

    Default [2.0b1a][SOLVED] data.Node traversal when passing additional arguments?

    [2.0b1a][SOLVED] data.Node traversal when passing additional arguments?


    originally reported by @hendricd in this thread for Ext 1.1.x:
    http://www.sencha.com/forum/showthread.php?t=12555

    Quote Originally Posted by hendricd View Post
    Recently used the cascade methods of data.Node and discovered some odd behaviour with passing additional arguments. If additional arguments are passed, they 'call'ed rather than 'apply'ed, making for a confusing debug session. The arguments you specify are passed as an array of arguments rather than what might be expected elsewhere within the framework (fn.apply(scope,arguments)):

    Code:
    Ext.override(Ext.data.Node,{ 
    
        /**
         * Bubbles up the tree from this node, calling the specified function with each node. The scope (<i>this</i>) of
         * function call will be the scope provided or the current node. The arguments to the function
         * will be the args provided or the current node. If the function returns false at any point,
         * the bubble is stopped.
         * @param {Function} fn The function to call
         * @param {Object} scope (optional) The scope of the function (defaults to current node)
         * @param {Array} args (optional) The args to call the function with (default to passing the current node)
         */
        bubble : function(fn, scope, args){
            var p = this;
            while(p){
    //          if(fn.call(scope || p, args || p) === false){
                if(fn.apply(scope || p, args || [p]) === false){
                    break;
                }
                p = p.parentNode;
            }
        },
    
        /**
         * Cascades down the tree from this node, calling the specified function with each node. The scope (<i>this</i>) of
         * function call will be the scope provided or the current node. The arguments to the function
         * will be the args provided or the current node. If the function returns false at any point,
         * the cascade is stopped on that branch.
         * @param {Function} fn The function to call
         * @param {Object} scope (optional) The scope of the function (defaults to current node)
         * @param {Array} args (optional) The args to call the function with (default to passing the current node)
         */
        cascade : function(fn, scope, args){
            //if(fn.call(scope || this, args || this) !== false){
            if(fn.apply(scope || this, args || [this]) !== false){
                var cs = this.childNodes;
                for(var i = 0, len = cs.length; i < len; i++) {
                	cs[i].cascade(fn, scope, args);
                }
            }
        },
    
        /**
         * Interates the child nodes of this node, calling the specified function with each node. The scope (<i>this</i>) of
         * function call will be the scope provided or the current node. The arguments to the function
         * will be the args provided or the current node. If the function returns false at any point,
         * the iteration stops.
         * @param {Function} fn The function to call
         * @param {Object} scope (optional) The scope of the function (defaults to current node)
         * @param {Array} args (optional) The args to call the function with (default to passing the current node)
         */
        eachChild : function(fn, scope, args){
            var cs = this.childNodes;
            for(var i = 0, len = cs.length; i < len; i++) {
                   //if(fn.call(scope || this, args || cs[i]) === false){
            	if(fn.apply(scope || this, args || [cs[i]]) === false){
            	    break;
            	}
            }
        }
    });
    By design ?

    re-reported in 2.x bugs on user request.

  2. #2
    Sencha - Community Support Team hendricd's Avatar
    Join Date
    Aug 2007
    Location
    Long Island, NY USA
    Posts
    5,963
    Vote Rating
    10
    hendricd will become famous soon enough hendricd will become famous soon enough

      0  

    Default


    And, Ext.Container:bubble, cascade have the same problem.

    Here are fixes for 2.0b+:

    Code:
    Ext.override(Ext.data.Tree,{ 
    
        /**
         * Bubbles up the tree from this node, calling the specified function with each node. The scope (<i>this</i>) of
         * function call will be the scope provided or the current node. The arguments to the function
         * will be the args provided or the current node. If the function returns false at any point,
         * the bubble is stopped.
         * @param {Function} fn The function to call
         * @param {Object} scope (optional) The scope of the function (defaults to current node)
         * @param {Array} args (optional) The args to call the function with (default to passing the current node)
         */
        bubble : function(fn, scope, args){
            var p = this;
            while(p){
                if(fn.apply(scope || p, args || [p]) === false){
                    break;
                }
                p = p.parentNode;
            }
        },
    
        /**
         * Cascades down the tree from this node, calling the specified function with each node. The scope (<i>this</i>) of
         * function call will be the scope provided or the current node. The arguments to the function
         * will be the args provided or the current node. If the function returns false at any point,
         * the cascade is stopped on that branch.
         * @param {Function} fn The function to call
         * @param {Object} scope (optional) The scope of the function (defaults to current node)
         * @param {Array} args (optional) The args to call the function with (default to passing the current node)
         */
        cascade : function(fn, scope, args){
            if(fn.apply(scope || this, args || [this]) !== false){
                var cs = this.childNodes;
                for(var i = 0, len = cs.length; i < len; i++) {
                    cs[i].cascade(fn, scope, args);
                }
            }
        },
    
        /**
         * Interates the child nodes of this node, calling the specified function with each node. The scope (<i>this</i>) of
         * function call will be the scope provided or the current node. The arguments to the function
         * will be the args provided or the current node. If the function returns false at any point,
         * the iteration stops.
         * @param {Function} fn The function to call
         * @param {Object} scope (optional) The scope of the function (defaults to current node)
         * @param {Array} args (optional) The args to call the function with (default to passing the current node)
         */
        eachChild : function(fn, scope, args){
            var cs = this.childNodes;
            for(var i = 0, len = cs.length; i < len; i++) {
                if(fn.apply(scope || this, args || [cs[i]]) === false){
                    break;
                }
            }
        }
    });
    
    Ext.override (Ext.Container,{ 
      bubble : function(fn, scope, args){
            var p = this;
            while(p){
                if(fn.apply(scope || p, args || [p]) === false){
            //  if(fn.call(scope || p, args || p) === false){
                    break;
                }
                p = p.ownerCt;
            }
        },
    
      cascade : function(fn, scope, args){
          //if(fn.call(scope || this, args || this) !== false){
            if(fn.apply(scope || this, args || [this]) !== false){
               if(this.items){
                    var cs = this.items.items;
                    for(var i = 0, len = cs.length; i < len; i++){
                    
                        if(cs[i].cascade){
                            cs[i].cascade(fn, scope, args);
                        }
                    }
                }
            }
        }
    });
    [tags: cascade bubble eachChild parameters Container Tree]
    "be dom-ready..."
    Doug Hendricks

    Maintaining ux: ManagedIFrame, MIF2 (FAQ, Wiki), ux.Media/Flash, AudioEvents, ux.Chart[Fusion,OFC,amChart], ext-basex.js/$JIT, Documentation Site.


    Got Sencha licensing questions? Find out more here.


  3. #3
    Sencha - Community Support Team jsakalos's Avatar
    Join Date
    Apr 2007
    Location
    Slovakia
    Posts
    27,538
    Vote Rating
    380
    jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future

      0  

    Default


    Thank you for posting. We will take a look at it and we will inform you when fixed.
    Jozef Sakalos, aka Saki

    Education, extensions and services for developers at new http://extjs.eu
    News: Grid Search Plugin, ExtJS 5 Complex Data Binding using MVVM


  4. #4
    Sencha User jack.slocum's Avatar
    Join Date
    Mar 2007
    Location
    Tampa, FL
    Posts
    6,955
    Vote Rating
    17
    jack.slocum will become famous soon enough jack.slocum will become famous soon enough

      0  

    Default


    Will be fixed in next check in, thanks.
    Jack Slocum
    Ext JS Founder
    Original author of Ext JS 1, 2 & 3.
    Twitter: @jackslocum
    jack@extjs.com