Results 1 to 2 of 2

Thread: Treepanel - appenChild to node problem

  1. #1
    Sencha User
    Join Date
    May 2014
    Posts
    18
    Answers
    1

    Default Answered: Treepanel - appenChild to node problem

    In my treepanel, I have a button to insert a Folder in the tree through an AJAX request. The AJAX response returns the id of the new inserted node (child_id) and the id of the parent of this node (parent_id).

    Then, I use the parent_id to get its data.Record instance, and the appendChild method to create the new folder with the child_id.

    The folder is created under the right node with the correct id, however, I dont know why but all the tree is inserted under that node as children. If I reload the tree from the server, everything is now correct.

    Code:
    var contextMenu = new Ext.menu.Menu({
        items: [{
          text: 'New Folder',
          handler: function(thisBtn,event){
                     var tree = Ext.getCmp('tree');
                     var record = tree.getSelectionModel().getSelection();
                     var id = record[0].data.id;
                     Ext.Ajax.request({
                       url: '/basqui/tree/insertFolder',
                       method: 'POST',
                       params: { 'id': id },
                       success: function(r){
                                       child_id = Ext.decode(r.responseText).child_id;
                                       parent = store.getNodeById(Ext.decode(r.responseText).parent_id);
                                       parent.appendChild({
                                               id: child_id,
                                               name: "New Folder",
                                               type: "folder",
                                               leaf:  false
                                       });
                                     }
                     });
                    }
        }]

  2. I found the solution, I have to set an empty children property in the node definition

    Code:
    parent.appendChild({
                      id: child_id,                                            
                      name: "New Folder", 
                      type: "folder",                                            
                      leaf:  false,                                            
                      children: []                                    
    });

  3. #2
    Sencha User
    Join Date
    May 2014
    Posts
    18
    Answers
    1

    Default

    I found the solution, I have to set an empty children property in the node definition

    Code:
    parent.appendChild({
                      id: child_id,                                            
                      name: "New Folder", 
                      type: "folder",                                            
                      leaf:  false,                                            
                      children: []                                    
    });

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •