1. #1
    Sencha Premium Member Neilcoder's Avatar
    Join Date
    Apr 2011
    Location
    Ireland
    Posts
    264
    Vote Rating
    0
    Neilcoder is on a distinguished road

      0  

    Question JSON gets read into data.Store only when I'm stepping through breakpoints in Firefox

    JSON gets read into data.Store only when I'm stepping through breakpoints in Firefox


    Hi,

    I hope you can help, I have a grid setup that has JSON fed into a data.Store. When I run the code with break points it works fine and dandy, but if I run it without debugging, it doesn't work. What part of the documentation do I need to read to get my head around this?

    I think it is trying to read in the JSON before it has got a response from the callback, so I'm assumming there must be some kind of config option to allow the store and the grid the store is being held in to wait to render until after the JSON is recieved?

    Code:
    Ext.require(['*']);
    
    Ext.onReady(function(){
    
        Ext.regModel("Catalog", {
            fields: ['name' ],
            associations: [
                {type: 'hasMany', model: 'Relation',    name: 'relations'},
                {type: 'hasMany', model: 'Operator',    name: 'operators'}
            ],
            proxy: {
                type: 'rest',
                url : '../js/catalog.json',
                reader: {
                    type: 'json'
                }
            }
        });
    
        Ext.regModel("Relation", {
            fields: [
                'name'
            ],
            associations: [
                {type: 'hasMany', model: 'Column',    name: 'columns'}
            ]
        });
    
    
    
        var store = new Ext.data.Store({
            model: "Catalog"
        });
    
    
    
        Ext.regModel('RelationTableModel', {
            fields: [
                {name: 'name', mapping : 'name'}
            ]
        });
    
    
        var tablePanelData = [];
    
        var headers = [
            {header: "name", width: 160, sortable: false, dataIndex: 'name'}
        ];
    
            store.load({
                callback: function() {
                    var cat = store.first();
                    cat.relations().each(function(relation) {
    
                        var relName = relation.get('name');
                        tablePanelData.push({
                            name:relName
                        });
                    });
                }
            });
    
        console.log("tablePanelData:" + tablePanelData);
    
    
    
        Ext.each(tablePanelData,function(item)
        {
            console.log("Testing getRelationArray()" + item);
        });
    
    
        var tablePanelStore = new Ext.data.Store({
            model : 'RelationTableModel',
            data   : tablePanelData
        });
    
       var tablePanelGrid = new Ext.grid.GridPanel({
            id : 'tg',
            ddGroup          : 'tablePanelGridDDGroup',
            store            : tablePanelStore,
            enableDragDrop   : true,
            stripeRows       : true,
            headers: headers,
            autoExpandColumn : 'name',
            title : 'tables',
            enableColumnMove : false,
            enableHdMenu : false,
            width:150,
            height:600,
            autoHeight : true
        });
    
    
        var tablePanel = new Ext.Panel({
            width        : 150,
            height       : 600,
            renderTo     : 'tablepanel',
            x: 750,
            layout       : 'absolute',
            items        : [
            tablePanelGrid
            ]
        });
        
    
    });
    Hope you can help,

    Thanks
    Neil

  2. #2
    Sencha User fay's Avatar
    Join Date
    Apr 2007
    Location
    Ireland
    Posts
    1,750
    Vote Rating
    9
    fay will become famous soon enough fay will become famous soon enough

      0  

    Default


    The load() method is asynchronous, so you can't expect tablePanelData to have anything in it immediately after you call store.load() as you are doing above with the console.log - tablePanelData is going to be empty until the callback is completed.

  3. #3
    Sencha Premium Member Neilcoder's Avatar
    Join Date
    Apr 2011
    Location
    Ireland
    Posts
    264
    Vote Rating
    0
    Neilcoder is on a distinguished road

      0  

    Thumbs up ahhhhh!

    ahhhhh!


    Thanks for that , never really fully understood why certain code in examples was put inside load methods


    So I put the code for the gridpanel into the the load method and it works fine!

Similar Threads

  1. Read xmlData from store in IE6 and Firefox...
    By bzborow1 in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 3 Mar 2011, 9:35 AM
  2. Store using ScriptTagProxy not read json data
    By raphdom in forum Ext 3.x: Help & Discussion
    Replies: 1
    Last Post: 21 Jan 2011, 5:12 AM
  3. store read data from Json Data
    By szxiaoyin in forum Ext 3.x: Help & Discussion
    Replies: 1
    Last Post: 10 May 2010, 3:44 AM
  4. can to read json data
    By starstar in forum Ext 3.x: Help & Discussion
    Replies: 23
    Last Post: 30 Dec 2009, 7:45 AM

Thread Participants: 1

Tags for this Thread