Topic: rev 103: this.children.each is not a function error when adding a node

Hi,

I've upgraded my Mifjs tree copy to rev 103.  Now, whenever I add new nodes, I get the following error:

this.children.each is not a function        Line 388

The vicinity around line 388 is:

        recursive: function(fn, args){
                args=$splat(args);
                if(fn.apply(this, args)!==false){
                        this.children.each(function(node){
                                if(node.recursive(fn, args)===false){
                                        return false;
                                }
                        });
                }
                return this;
        }

What gives?

Thanks!

Re: rev 103: this.children.each is not a function error when adding a node

BTW, My MooTools version is:

        'version': '1.2.3',
        'build': '4980aa0fb74d2f6eb80bcd9f5b8e1fd6fbb8f607'

Re: rev 103: this.children.each is not a function error when adding a node

I've browsed throught the Demos folder in the trunk version, and I discovered that I needed to change my code.  Anyway, this code still doesn't work:

window.addEvent('domready', function () {
    tree = new Tree_serial({
        container   : $('tree_container'),
        types       : {
            folder  : {
                openIcon    : 'mif-tree-open-icon',
                closeIcon   : 'mif-tree-close-icon'
            }
        },
        dfltType    :   'folder',
        height      :   20
    })
    .load({
        url: '/my/json'
    });

    $('add_node').addEvent('click', function () {
        var node = tree.getSelected();
        var newNode = new Mif.Tree.Node({
            parentNode: node,
            tree: tree
        }, {property:{name: 'node1'}});

        tree.add(newNode, node, 'inside');
    });
});

Re: rev 103: this.children.each is not a function error when adding a node

Tree_serial?

Re: rev 103: this.children.each is not a function error when adding a node

Yikes, I forgot about Tree_serial:

var Tree_serial = new Class({
    Extends     : Mif.Tree,
    serialize   : function (items) {
        var serial = [];
        if (!items) {
            items = this.root.getChildren();
        }
        items.each(function (el, i) {
            var tmp = new Hash({
                    interfaceopt    :   el.interfaceopt,
                    name            :   el.name,
                    scheduler       :   el.scheduler,
                    enabled         :   el.enabled,
                    bandwidth       :   el.bandwidth,
                    bandwidthtype   :   el.bandwidthtype,  
                    children        :   (el.getChildren()) ? this.serialize(el.getChildren()) : []
            });

            serial[i] = tmp.filter(function (v, k) {
                return !(v === '' || v === null || v === undefined);
            });

        }, this);

        return serial;
    }
});

Re: rev 103: this.children.each is not a function error when adding a node

Aha, I think it might have something to do with my data... I'm verifying it now...


  • UPDATE 1: rev 103 works fine... I replaced my JSON source to a source that is known to be good and everything works as intended.  Now I only need to know what's wrong with my JSON... missing fields, perhaps?

  • UPDATE 2: OK, I discovered the problem... it turns out that I set some children fields as an empty array...

"children":[{"interfaceopt":"wan","name":"wan0","children":[]}]

Last edited by simoncpu (2009-10-19 11:23:34)