Results 1 to 9 of 9

Thread: NoteInterface.appendChild also adds the nodes to the parent list

    Success! Looks like we've fixed this one. According to our records the fix was applied for TOUCH-2550 in a recent build.
  1. #1
    Sencha Premium User
    Join Date
    Mar 2009
    Posts
    254

    Default NoteInterface.appendChild also adds the nodes to the parent list

    I have reported it earlier also, but it was marked as fixed, and nobody seems to be noticing my replies to that thread where I mention the issue continues to exist with Touch 2.0 release version.
    So I am creating a new thread with exactly same subject line.

    Here's the sample code to reproduce the issue:

    Code:
                    Ext.define('NavigationModel', {
                        extend: 'Ext.data.Model',
                        config: {
                            fields: ['path', 'text', 'size', 'mime', 'extension', { name: 'modified', type: 'date'}]
                        }
                    });
    
    
                    var lstNav = new Ext.NestedList({
                        title: 'Files',
                        floating: true,
                        width: 300,
                        height: 400,
                        store: Ext.create('Ext.data.TreeStore', {
                            model: 'NavigationModel',
                            root: {},
                            proxy: {
                                type: 'memory',
                                reader: {
                                    type: 'json',
                                    root: 'children'
                                }
                            }
                        })
                    });
                    Ext.Viewport.add(lstNav);
    
    
                    setTimeout(function () {
                        var rootNode = lstNav.getStore().getRoot();
                        //C:\ folder gets shwon twice.
                        rootNode.appendChild([
                            {
                                text: 'C:\\'
                            },
                            {
                                text: 'D:\\'
                            }
                        ]);
    
    
                        setTimeout(function () {
                            var child = rootNode.childNodes[0];
                            //Children are appended to parent list.
                            rootNode.appendChild([
                                {
                                    text: 'Folder1'
                                },
                                {
                                    text: 'Folder2'
                                }
                            ]);
    
    
                            //Child list is empty.
                            //lstNav.goToNode(child);
                        }, 1000);
                    }, 1000);
    The issue has been present consistently through Beta 2 I believe right upto the current release version.

    I have tried many permutations of the above code (while managing loaded/loading/leaf properties of NodeInterface manually) to somehow workaround this but it doesn't seem to be working.

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

    Default

    Have pushed up this bug. Thought I had come across another thread like this yesterday but can't find it.
    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 User
    Join Date
    Mar 2009
    Posts
    254

    Default

    Thanks Simon, here's the other thread:
    http://www.sencha.com/forum/showthread.php?155095-NoteInterface.appendChild-also-adds-the-nodes-to-the-parent-list

    It would be appreciated if the fix when it becomes available is posted here too so I can remove my hacky overrides and messy code to avoid this issue being seen in our application.

  4. #4
    Sencha User
    Join Date
    Mar 2007
    Location
    Haarlem, Netherlands
    Posts
    1,243

    Default

    Hi,

    The following override should fix your problem.

    Code:
    Ext.define('Ext.override.data.Store', {
        override: 'Ext.data.Store',
        
        /**
         * Inserts Model instances into the Store at the given index and fires the {@link #add} event.
         * See also <code>{@link #add}</code>.
         * @param {Number} index The start index at which to insert the passed Records.
         * @param {Ext.data.Model[]} records An Array of Ext.data.Model objects to add to the cache.
         */
        insert: function(index, records) {
            if (!Ext.isArray(records)) {
                records = Array.prototype.slice.call(arguments, 1);
            }
    
            var me = this,
                sync = false,
                data = this.data,
                ln = records.length,
                Model = this.getModel(),
                existingRecords = [],
                indices = [],
                modelDefaults = me.getModelDefaults(),
                i, record, added = false;
    
            records = records.slice();
    
            for (i = 0; i < ln; i++) {
                record = records[i];
                if (!record.isModel) {
                    record = new Model(record);
                }
                // If we are adding a record that is already an instance which was still in the
                // removed array, then we remove it from the removed array
                else if (this.removed.indexOf(record) != -1) {
                    Ext.Array.remove(this.removed, record);
                }
    
                // If the record already exists in our data collection then we don't add it again
                if (data.indexOf(record) !== -1) {
                    existingRecords.push(record);
                }
    
                record.set(modelDefaults);
                record.join(me);
    
                records[i] = record;
    
                // If this is a newly created record, then we might want to sync it later
                sync = sync || (record.phantom === true);
            }
    
            if (existingRecords.length) {
                for (i = 0, ln = existingRecords.length; i < ln; i++) {
                    record = existingRecords[i];
                    record._tmpIndex = data.indexOf(record);
                }
    
                Ext.Array.sort(existingRecords, function(record1, record2) {
                    return record1._tmpIndex < record2._tmpIndex ? 1 : -1;
                });
    
                for (i = 0; i < ln; i++) {
                    record = existingRecords[i];
                    indices.push(record._tmpIndex);
                    delete record._tmpIndex;
                }
    
                me.fireEvent('removerecords', me, existingRecords, indices);
            }
    
            // Now we insert all these records in one go to the collection. Saves many function
            // calls to data.insert. Does however create two loops over the records we are adding.
            if (ln === 1) {
                added = data.insert(index, records[0]);
                if (added) {
                    added = [added];
                }
            } else {
                added = data.insertAll(index, records);
            }
    
            if (added) {
                me.fireEvent('addrecords', me, added);
            }
    
            if (me.getAutoSync() && sync) {
                me.sync();
            }
    
            return records;
        }
    });

  5. #5
    Sencha Premium User
    Join Date
    Mar 2009
    Posts
    254

    Default

    Hi Tommy, sorry for the delay in response, I was travelling.

    The issue (after applying the mentioned override) still does NOT seem to be fully fixed. Please try this:

    Code:
    Ext.define('NavigationModel', {
        extend: 'Ext.data.Model',
        config: {
            fields: ['path', 'text', 'size', 'mime', 'extension', { name: 'modified', type: 'date'}]
        }
    });
    
    
    
    
    var lstNav = new Ext.NestedList({
        title: 'Files',
        floating: true,
        width: 300,
        height: 400,
        store: Ext.create('Ext.data.TreeStore', {
            model: 'NavigationModel',
            root: {},
            proxy: {
                type: 'memory',
                reader: {
                    type: 'json',
                    root: 'children'
                }
            }
        })
    });
    Ext.Viewport.add(lstNav);
    
    
    
    
    setTimeout(function () {
        var rootNode = lstNav.getStore().getRoot();
        rootNode.appendChild([
            {
                text: 'C:\\'
            },
            {
                text: 'D:\\'
            }
        ]);
    
    
    
    
        setTimeout(function () {
            var child = rootNode.childNodes[0];
            //Children are appended to parent list as well as child list.
            child.appendChild([
                {
                    text: 'Folder1'
                },
                {
                    text: 'Folder2'
                }
            ]);
    
    
            //Folder 1 and Folder 2 get appended to root node as well.
            lstNav.goToNode(child);
        }, 1000);
    }, 1000);
    In the above sample code, "Folder 1" and "Folder 2" get appended to root node as well whereas they were appended to "C:\" node.

  6. #6
    Sencha User
    Join Date
    Mar 2007
    Location
    Haarlem, Netherlands
    Posts
    1,243

    Default

    Hi r_honey,

    Can you also apply the following override?

    Code:
    Ext.define('Ext.data.override.NodeStore', {
        override: 'Ext.data.NodeStore',
    
        isVisible: function(node) {
            var parent = node.parentNode;
    
            if (!this.getRecursive() && parent !== this.getNode()) {
                return false;
            }
    
            while (parent) {
                if (!parent.isExpanded()) {
                    return false;
                }
    
                //we need to check this because for a nodestore the node is not likely to be the root
                //so we stop going up the chain when we hit the original node as we don't care about any
                //ancestors above the configured node
                if (parent === this.getNode()) {
                    break;
                }
    
                parent = parent.parentNode;
            }
            return true;
        }
    });

  7. #7
    Sencha Premium User
    Join Date
    Mar 2009
    Posts
    254

    Default

    Thanks Tommy, the issue seems to be resolved by applying the 2 overrides together. Hopefully I won;t have to go back to my hacky code again

  8. #8
    Sencha User
    Join Date
    Mar 2007
    Location
    Haarlem, Netherlands
    Posts
    1,243

    Default

    Great! I hope so too

    Thanks again for the reports.

  9. #9
    Sencha Premium User
    Join Date
    Mar 2009
    Posts
    254

    Default

    Hi Tommy, the fix introduces another issue.

    Consider the following sequence of events where you have a store bound to a DataView:

    Code:
    var records = [{name: 'P1', email: '[email protected]'}, {name: 'P2', email: '[email protected]'}];
    store.add(records);
    
    setTimeout(function() {
      store.removeAll();
    
      setTimeout(function() {
        store.add(records);
      }, 2000);
    }, 2000);
    The second call to store.add(records) generates an exception in moveItemsToCache method of Ext.dataview.element.Container.

Posting Permissions

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