1. #1
    Sencha User
    Join Date
    Mar 2012
    Posts
    8
    Vote Rating
    0
    gergar28 is on a distinguished road

      0  

    Default SOLVED: Load store from a variable.

    SOLVED: Load store from a variable.


    SOLVED:
    Hi again.
    Im tryin to load a storage from a variable. in this moment i'm work in the same way.

    in app.js (i have the default MVC architecture) i define "respJson":

    Code:
    var me = this;
    var respJson = null;
    Later, in the "launch: function()" block i make a xml ajax request, and this response i convert to json, and store in respJon like that:


    Code:
    launch: function() {        // Destroy the #appLoadingIndicator element
            Ext.fly('appLoadingIndicator').destroy();
            
            Ext.Ajax.request({
                url: 'http://localhost:8081/someApp/SomeWebServiceResponseXml',
                params: {    
                    component: 'SomeParam',
                    userid: 'id',
                    password: 'pass'
                },
                method: 'GET',
                success: function(response, opts) {
                    
                    me.respJson = Ext.JSON.encode(me.ConvertXmlToJson(response.responseXML);
                    console.log(me.respJson);
                    
                }
            });
    
    
            // Initialize the main view
            Ext.Viewport.add(Ext.create('App.view.Main'));
        }
    Now in my store (i'm use a proxy memory) have the following code:
    (MyApp/app/store/myStore.js)
    Code:
    Ext.define('App.store.myStore', {
        extend: 'Ext.data.TreeStore',
        
        requires: [
            'App.model.myModel'
        ],
        
        
        config: {
            autoLoad: true,
            model: 'App.model.myModel',
           data: me.respJson,   //For some reason my var "respJson" is null (i do a alert(me.respJson); )
            proxy: {
                       type: 'memory',
                       reader: {
                           type: 'json',
                           rootProperty: 'file'
            }
        }
        
        }
    });
    I try to call respJson i this way too: data: 'MyApp.app.respJson', and i get the same result (null)

    Note: if i take the content of respJson, copy and paste in some file "data.json" and call it in this way:
    Code:
    proxy: {            type: 'ajax',
                url: 'resources/data/data.json',
                reader: {
                    type: 'json',
                    rootProperty: 'file'
                }
          }
    My app work awsome, but is not the solution that i want .

    Why my respJson variable are initialized?
    Some help to use global variables?, im search for "global variables" in the forums and i only find what i call "global constant".

    Thanks in advance!
    Gerardo garrido.

  2. #2
    Sencha User
    Join Date
    Mar 2012
    Posts
    8
    Vote Rating
    0
    gergar28 is on a distinguished road

      0  

    Default


    I resolved this problem in this way.
    In the load: function() block y add the followings lines:

    Code:
    if(Ext.getStore('turboStore') != null){
                        console.log("se lee el store");
                        var store = Ext.getStore('turboStore');
                        store.setData(me.respJson);
                        Ext.getStore('turboStore').sync();
                        }
    Now my launch: function is like that:

    Code:
    launch: function() {        // Destroy the #appLoadingIndicator element
            Ext.fly('appLoadingIndicator').destroy();
            
            Ext.Ajax.request({
                url: 'http://localhost:8081/someApp/SomeWebServiceResponseXml',
                params: {    
                    component: 'SomeParam',
                    userid: 'id',
                    password: 'pass'
                },
                method: 'GET',
                success: function(response, opts) {
                    
                    me.respJson = Ext.JSON.encode(me.ConvertXmlToJson(response.responseXML);
                    console.log(me.respJson);
                    
                    if(Ext.getStore('turboStore') != null){  //The magic!			console.log("se lee el store");
    			var store = Ext.getStore('turboStore');
    			store.setData(me.respJson);
    			Ext.getStore('turboStore').sync();
    			}
                    
                }
            });
    
    
    
    
            // Initialize the main view
            Ext.Viewport.add(Ext.create('App.view.Main'));
        }
    Finally i deleted the "data" parameter in myStore and add an storeId, like that:

    Code:
    Ext.define('App.store.myStore', {
        extend: 'Ext.data.TreeStore',
        
        requires: [
            'App.model.myModel'
        ],
        
        
        config: {
            autoLoad: true,
            model: 'App.model.myModel',
            storeId: 'turboStore',
            proxy: {
                       type: 'memory',
                       reader: {
                           type: 'json',
                           rootProperty: 'file'
            }
        }
        
        }
    });
    Thx for read

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar