Results 1 to 7 of 7

Thread: Save Data From Ext.Ajax.request into Ext.Store

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Sencha User
    Join Date
    Aug 2011
    Posts
    12
    Vote Rating
    0
      0  

    Default Save Data From Ext.Ajax.request into Ext.Store

    Hi all,
    I am calling an ASP.NET web service that returns JSON data with two roots, using Ext.Ajax.request and i am handling the returned response successfully.
    What i need to do is to save this JSON data to a new Ext.Store.
    I know that i can call the web service directly from the store, but in my case the returned JSON data have multiple roots so i can save each root into a store.
    This is my code:
    Code:
    Ext.regModel('GendersModel', {
    			fields:[					
    				{name:'GenderID'},
    				{name:'GenderDescription'},
    				{name:'GenderPicture'}	
    			]
    		});
    		Ext.regModel('CompositionModel', {
    			fields:[					
    				{name:'CompositionID'},
    				{name:'CompositionDescription'}
    			]
    		});
    
    var GendersStore = new Ext.data.Store({
    			id: 'GendersStore',						   
    			model: 'GendersModel',							   
    			listeners: {
    				beforeload: function(myStore, options) {
    				},
    				load: function(myStore, records, options) {
    					console.log('Genders' + myStore.getCount());					 
    				},
    				exception: function(misc) {						
    				}
    			}											  
    		});
    var CompositionStore = new Ext.data.Store({
    			id: 'CompositionStore',						   
    			model: 'CompositionModel',							   
    			listeners: {
    				beforeload: function(myStore, options) {
    				},
    				load: function(myStore, records, options) {
    					console.log('Composition' + myStore.getCount());					 
    				},
    				exception: function(misc) {						
    				}
    			}											  
    		});
    
    Ext.Ajax.request({
    url:myURL,	 
    method: 'GET',
    jsonData: { "Alert": {} },
    headers: { 'Content-Type': 'application/json;charset=utf-8' },
    success: function (response, opts) {  
    var json = Ext.decode(response.responseText); 
    console.log(json); //the returned json is valid.
    
    //here i want to save the json to Genders store and Composition store. 
    //i have tried this, but it is not working:
    GendersStore.loadData(json);
    CompositionStore.loadData(json);
    },
    failure: function (response, opts) {
    alert('Error calling server.');
    }
    });
    I need to make it in this way because i want to make only one call to the web service, get the data, fill two stores, i dont want to make multiple calls.

    This is my JSON data:
    Code:
    "{"list1":[{"GenderID":1,"GenderDescription":"Gender1","GenderPicture":"/ipadcatalog/pictures/bundle.png"},{"GenderID":2,"GenderDescription":"Gender2","GenderPicture":"/ipadcatalog/pictures/bundle.png"},{"GenderID":3,"GenderDescription":"Gender3","GenderPicture":"/ipadcatalog/pictures/bundle.png"}],"list2":[{"CompositionID":1,"CompositionDescription":"Nylon"},{"CompositionID":2,"CompositionDescription":"Coton"},{"CompositionID":3,"CompositionDescription":"Leather"}]}"
    


    Please i need help with this issue.

    Thank you in advance.

  2. #2
    Sencha User
    Join Date
    Sep 2011
    Location
    Indonesia
    Posts
    23
    Vote Rating
    0
      0  

    Default

    I suppose that you can set your store a local storage (make sure the proxy of the model and the store are set to local storage).

    After you get the response text, you need to decode the Ajax response and after that you create an instance of the model store and parse the data from the AJAX response and insert it to the model. After that you can add the model manually to the store using store.add().

    Hope this help .

  3. #3
    Sencha User
    Join Date
    Aug 2011
    Posts
    12
    Vote Rating
    0
      0  

    Default

    Thank you hihiapolla for your help, but i managed to make it work.
    If anyone is intrested how i did it, i have no problem sharing it.

    Regards,

  4. #4
    Sencha User
    Join Date
    Mar 2012
    Posts
    8
    Vote Rating
    0
      0  

    Default

    how do you doing to solved this issue?

    can you send me some example please


    thank for all

  5. #5
    Sencha User
    Join Date
    Mar 2012
    Posts
    104
    Answers
    4
    Vote Rating
    0
      0  

    Default

    I'm interested too, please, could you sharing your code?

  6. #6
    Sencha User
    Join Date
    Mar 2012
    Posts
    8
    Vote Rating
    0
      0  

    Default

    i solved my problem in this issue http://www.sencha.com/forum/showthre...om-a-variable.

    regards.

Posting Permissions

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