1. #1
    Sencha User
    Join Date
    Aug 2011
    Posts
    12
    Vote Rating
    0
    moulezim is on a distinguished road

      0  

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

    Unanswered: 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
    hihiapolla is on a distinguished road

      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
    moulezim is on a distinguished road

      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
    gergar28 is on a distinguished road

      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
    izak18 is on a distinguished road

      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
    gergar28 is on a distinguished road

      0  

    Default


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

    regards.

  7. #7
    Sencha User
    Join Date
    Mar 2012
    Posts
    104
    Answers
    4
    Vote Rating
    0
    izak18 is on a distinguished road

      0  

    Default


    Thanks but this method is in sencha touch 2.0.
    I'm using 1.0 and I have a problem when I try to set data in my store, I get this error message:

    Uncaught TypeError: Object [object Object] has no method 'setData'

    What can I do?

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi