Results 1 to 3 of 3

Thread: Moving code to function causes problems

  1. #1
    Sencha Premium Member
    Join Date
    Aug 2012
    Posts
    43
    Answers
    2

    Default Moving code to function causes problems

    I started with the following code:

    Code:
        refreshUIAfterDeletion: function() {
            var treeSel = this.getTreeNodeSelection(),
                me = this;
            
            if (treeSel !== null) {
                    this.getGridCmp().getStore().reload();
                    
                    if (treeSel.isExpanded() || treeSel.hasChildNodes()) {
                        treeSel.collapse(
                            false,
                            function() {
                                treeSel.removeAll(false, true);
                                treeSel.set('loaded', false); // mark as unloaded, ensure plus sign shown
                            },
                            me);
                    }
                }
            }
        },
    This all works fine.

    But I needed that code to collapse and remove the children in a separate function, so I changed it to be:

    Code:
        collapseTreeNodeRemoveChildren: function(node) {
            var me = this;
            
            node.collapse(
                false,
                function() {
                    node.removeAll(false, true);
                    node.set('loaded', false); // mark as unloaded, ensure plus sign shown
                },
                me
            );
        },
    
        refreshUIAfterDeletion: function() {
            var treeSel = this.getTreeNodeSelection(),
                me = this;
            
            if (treeSel !== null) {
                    this.getGridCmp().getStore().reload();
                    
                    if (treeSel.isExpanded() || treeSel.hasChildNodes()) {
                        this.collapseTreeNodeRemoveChildren(treeSel);
                    }
                }
            }
        },
    The tree gets updated fine, but now the grid refresh doesn't work. That seems really weird to me. Can anyone explain this, and even better, suggest a solution?

    BTW, in order to not have the removeAll() call to not POST to the server (once for each child), I had to change removeAll(true) to be removeAll(false).

    This means the nodes aren't being destroyed. Is there any downside to this? Is this a memory leak? Is there another/better way to avoid the POSTs to the server?

    Thank you,


    Brian

  2. #2
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,448
    Answers
    3997

    Default

    The grid doesn't refresh now? That call wasn't changed.
    Mitchell Simoens @LikelyMitch

    Check out my GitHub:
    https://github.com/mitchellsimoens

    Posts are my own, not any current, past or future employer's.

  3. #3
    Sencha Premium Member
    Join Date
    Aug 2012
    Posts
    43
    Answers
    2

    Default

    Yes, I know, hence my confusion and bewilderment.

    I solved it with a hack. Now just before I collapse the node, I set a global variable to remember that. I then collapse the node, but don't supply a callback to delete the children. Instead, I created a handler for the collapsed event, and do everything there.

    This is not ideal, but it's better than duplicated code, which is what I'd have to do if I didn't put that code into a separate function.

Posting Permissions

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