Success! Looks like we've fixed this one. According to our records the fix was applied for TOUCH-2285 in a recent build.
  1. #1
    Sencha User
    Join Date
    Jan 2011
    Posts
    14
    Vote Rating
    0
    jlwarren1 is on a distinguished road

      0  

    Default Infinite loop in nested list when loading json through proxy

    Infinite loop in nested list when loading json through proxy



    Sench Touch version tested:
    • Sencha Touch 2.0 RC2
    • Sencha Touch 2.0 RC1
    Browser versions tested against:
    • Chrome
    • Safari iOS
    • Android
    Description:
    • When using a nested list attached to a tree store that loads json data via proxy. If you tap on an empty node the nested list repeats back to the root. This crates an infinite loop.
    Steps to reproduce the problem:
    • Create nested list
    • Attach tree store to nested list
    • Load tree store data via proxy (json)
    • Data contains empty children node (see groceries.json code below)
    • Tap on parent node with no children (in the example below tap on "Fruit")
    The result that was expected:
    • empty list should show when tapping on empty parent node
    The result that occurs instead:
    • The empty list is replaced by the root
    • Infinite Loop (All though infinite loops are cool, they are not very useful)
    Test Case:
    app.js
    Code:
     Ext.define('ListItem', {
         extend: 'Ext.data.Model',
         config: {
             fields: [{
                 name: 'text',
                 type: 'string'
             }]
         }
     });
    
    
     var store = Ext.create('Ext.data.TreeStore', {
         model: 'ListItem',
         defaultRootProperty: 'items',
         proxy: {
            type: 'ajax',
            root: {},
            url: 'groceries.json'
        }
     });
    
    
    Ext.application({
        name: 'Classifieds',
      
        launch: function() {
            var nestedList = Ext.create('Ext.NestedList', {
                 fullscreen: true,
                 title: 'Groceries',
                 displayField: 'text',
                 store: store
             });
            
        }
    });
    groceries.json:
    Code:
    {     text: 'Groceries',
         items: [{
             text: 'Drinks',
             items: [{
                 text: 'Water',
                 items: [{
                     text: 'Sparkling',
                     leaf: true
                 }, {
                     text: 'Still',
                     leaf: true
                 }]
             }, {
                 text: 'Coffee',
                 leaf: true
             }, {
                 text: 'Espresso',
                 leaf: true
             }, {
                 text: 'Redbull',
                 leaf: true
             }, {
                 text: 'Coke',
                 leaf: true
             }, {
                 text: 'Diet Coke',
                 leaf: true
             }]
         }, {
             text: 'Fruit',
             items: []
         }, {
             text: 'Snacks',
             items: [{
                 text: 'Nuts',
                 leaf: true
             }, {
                 text: 'Pretzels',
                 leaf: true
             }, {
                 text: 'Wasabi Peas',
                 leaf: true
             }]
         }]
     }

    Possible fix:
    • None
    Additional CSS used:
    • none

  2. #2
    Sencha User Jamie Avins's Avatar
    Join Date
    Mar 2007
    Location
    Redwood City, California
    Posts
    3,661
    Vote Rating
    20
    Jamie Avins is a jewel in the rough Jamie Avins is a jewel in the rough Jamie Avins is a jewel in the rough

      0  

    Default


    Thank you for the report.

    Sencha Inc

    Jamie Avins

    @jamieavins

  3. #3
    Sencha User
    Join Date
    Mar 2007
    Location
    Haarlem, Netherlands
    Posts
    1,243
    Vote Rating
    10
    TommyMaintz will become famous soon enough TommyMaintz will become famous soon enough

      0  

    Default


    Thanks for this awesome test case! It made it possible to hunt down this issue very quickly, and is an example for how bug reports should be in order for us to quickly find and fix the problem.

    Two minor things for next time. Ext.create calls should always be made inside of the launch and valid JSON data uses double quotes around keys and values. But this is just nitpicky and in this case not of importance. Thought I would just point them out to be annoying :p

    Anyway, here is your test case with an override at the top that makes it work until the next release. Let me know if you still experience any problems after applying this override.

    Code:
            Ext.define('Ext.data.TreeStoreOverride', {
                override: 'Ext.data.TreeStore',
                
                onNodeAppend: function(parent, node) {
                    var proxy = this.getProxy(),
                        reader = proxy.getReader(),
                        data = node.raw,
                        records = [],
                        rootProperty = reader.getRootProperty(),
                        dataRoot, processedData, i, ln;
            
                    if (!node.isLeaf()) {
                        dataRoot = reader.getRoot(data);
                        if (dataRoot) {
                            processedData = reader.extractData(dataRoot);
                            for (i = 0, ln = processedData.length; i < ln; i++) {
                                if (processedData[i].node[rootProperty]) {
                                    processedData[i].data[rootProperty] = processedData[i].node[rootProperty];
                                }
                                records.push(processedData[i].data);
                            }
            
                            // If the child record is not a leaf, and it has a data root (e.g. items: [])
                            // and there are items in this data root, then we call fillNode to automatically
                            // add these items. fillNode sets the loaded property on the node, meaning that
                            // the next time you expand that node, it's not going to the server to request the
                            // children. If however you pass back an empty array as items, we have to set the
                            // loaded property to true here as well to prevent the items from being be loaded
                            // from the server the next time you expand it.
                            // If you want to have the items loaded on the next expand, then the data for the
                            // node should not contain the items: [] array.
                            if (records.length) {
                                this.fillNode(node, records);
                            } else {
                                node.set('loaded', true);
                            }
                            delete data[rootProperty];
                        }
                    }
                }
            });
            
            Ext.define('ListItem', {
                 extend: 'Ext.data.Model',
                 config: {
                     fields: [{
                         name: 'text',
                         type: 'string'
                     }]
                 }
             });
    
            Ext.application({
                name: 'Classifieds',
    
                launch: function() {
                    var store = Ext.create('Ext.data.TreeStore', {
                        model: 'ListItem',
                        defaultRootProperty: 'items',
                        proxy: {
                           type: 'ajax',
                           root: {},
                           url: 'groceries.json'
                       }
                    });
    
                    var nestedList = Ext.create('Ext.NestedList', {
                         fullscreen: true,
                         title: 'Groceries',
                         displayField: 'text',
                         store: store
                    });
                }
            });

  4. #4
    Sencha User
    Join Date
    Jan 2011
    Posts
    14
    Vote Rating
    0
    jlwarren1 is on a distinguished road

      0  

    Default


    That Fixed it! Thanks for the quick reply.

Thread Participants: 2