1. #1
    Sencha User
    Join Date
    Nov 2012
    Posts
    6
    Vote Rating
    0
    richiejaeger is on a distinguished road

      0  

    Default Unanswered: Tree has to be collapsed to appendChild?!

    Unanswered: Tree has to be collapsed to appendChild?!


    Hey,

    i got the following function to add new childs to an existing node:

    Code:
    saveModule: function(button) {
            var win = button.up('window'),
                form = win.down('form').getForm(),
                tree = this.getController('Format').getFormatSelection(),
                store = tree.getStore(),
                parent = tree.getSelectionModel().getSelection()[0],
                node = store.getNodeById(parent.getId());
    
    
            if (form.isValid()) {
                //tree.collapseAll();
                
                var record = node.createNode({ name: form.findField('module_id').getStore().findRecord('id', form.getFieldValues().module_id).get('name'), leaf: true, parentId: parent.getId() });
                node.appendChild(record);
                record.save({
                    success: function() {
                        win.close();
                        store.reload();
                    }
                });
            }
        }
    The node gets created via my proxy. I can also find the new record in my Database. But i get an error, if i add the childnode to an expanded node:

    Uncaught TypeError: Cannot read property 'internalId' of undefined
    If i add an record to an collapsed node, i dont get any error...

    Is this problem known or am i just doing something wrong?!

    Regards
    Richie

  2. #2
    Sencha - Support Team slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    4,795
    Answers
    358
    Vote Rating
    167
    slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold

      0  

    Default


    This works for me in 4.2:
    You want to see if it fails when you try with it?

    Code:
    var store = Ext.create('Ext.data.TreeStore', {
        root: {
            expanded: true,
            children: [
                { text: "detention", leaf: true },
                { text: "homework", expanded: true, children: [
                    { text: "book report", leaf: true },
                    { text: "algebra", leaf: true}
                ] },
                { text: "buy lottery tickets", leaf: true }
            ]
        }
    });
    
    
    Ext.create('Ext.tree.Panel', {
        title: 'Simple Tree',
        width: 200,
        height: 220,
        store: store,
        rootVisible: false,
        renderTo: Ext.getBody()
        , tbar: [{
            text: 'Add node'
            , handler: function (btn) {
                var dest = btn.up('treepanel').getRootNode().getChildAt(1);
                dest.appendChild({text: 'added', leaf: true});
            }
        }]
    });

Thread Participants: 1

Tags for this Thread