Results 1 to 4 of 4

Thread: Loading JSON into a Store from Ajax request

  1. #1
    Sencha User
    Join Date
    Nov 2012
    Posts
    12
    Vote Rating
    0
      0  

    Default Unanswered: Loading JSON into a Store from Ajax request

    I am trying to load some JSON data and it is throwing a Object doesn't support this property or method error.

    This is the data in a JSON file i am loading and it is returning fine:

    Code:
    {    "data": [
        {
            "id": 1,
            "source": "1445261",
            "target": "1437043",
            "sourceType": "user",
            "redirectUrl": "http://www.google.co.uk",
            "message": "this is a notification message",
            "targetType": "user",
            "messageType": "notification",
            "sentDate": "1354758001",
            "notificationType": "notification",
            "parameters": "null",
            "read": "false",
            "readDate": 1354758001
        }
        ]
    }
    This is the Store and associated ajax request:

    Code:
    var infoStagingStore = Ext.create('Ext.data.Store', {
    	model: 'SCB.RMWB.InfoBar.Model.Message',
    	storeId: 'Staging',
    	autoLoad: false,
    	pageSize: 10,
    	proxy: {
            type: 'ajax',
            reader: {
            	type: 'json',
            	root: 'data'
            }
        },
        listeners: {
        	load: function(){
        		console.log('loaded');
        	}
        }	
    });
    
    
    Ext.Ajax.request({
        url: '/rmwb/resources/js/app/infoBar/data/data.json',
        timeout: 60000,
        method: 'GET',
        scope: this,
        success: function(resp) {
        	console.log(resp.responseText);
        	var store = Ext.data.StoreManager.lookup('Staging');
        	store.loadRawData(Ext.JSON.decode(resp.responseText), true);
        },
        failure: function(resp, opts) {
    
    
        },
        callback: function(options, success, resp) {
        }
    });

  2. #2
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    18,387
    Answers
    649
    Vote Rating
    858
      0  

    Default

    Why are you doing it like that? Just load it via the proxy, doing a separate ajax request is just making more work.
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  3. #3
    Sencha User
    Join Date
    Nov 2012
    Posts
    12
    Vote Rating
    0
      0  

    Default

    A fair point.

    I tried this which is fine:

    Code:
    var infoStagingStore = Ext.create('Ext.data.Store', {
    	model: 'SCB.RMWB.InfoBar.Model.Message',
    	storeId: 'Staging',
    	autoLoad: true,
    	proxy: {
            type: 'ajax',
            url: '/rmwb/resources/js/app/infoBar/data/data.json',
            reader: {
            	type: 'json',
            	root: 'data'
            }
        },
        listeners: {
        	load: function(){
        		console.log('loaded');
        	}
        }	
    });
    But how do i load data into a pagingmemory store on page load from the server?

    Would i need to load the data from the above store to a subsequent pagingmemory store.

    The requirement is to pull historical data from the server and then accept new data via polling which will then be added to the pagingmemory store.

    Apologies for not being clear on requirements.

  4. #4
    Sencha User
    Join Date
    Nov 2012
    Posts
    12
    Vote Rating
    0
      0  

    Default

    Would the following work?

    Code:
    var infoStagingStore = Ext.create('Ext.data.Store', {
        model: 'SCB.RMWB.InfoBar.Model.Message',
        storeId: 'Staging',
        autoLoad: true,
        proxy: {
            type: 'ajax',
            url: '/rmwb/resources/js/app/infoBar/data/data.json',
            reader: {
                type: 'json',
                root: 'data'
            }
        },
        listeners: {
            load: function(){
                console.log(this.getProxy().type);
                this.getProxy().type = 'pagingmemory';
                console.log(this.getProxy().type);
                console.log('loaded');
            }
        }    
    });
    So the store then becomes a paging memory type and then i can manually add records to the store.

    I need the ability to page in memory the historical data and the new polling data as it comes in.

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
  •