Results 1 to 7 of 7

Thread: Can't access store at first start, but after 2nd start its working... Why??

  1. #1
    Sencha User
    Join Date
    May 2012
    Posts
    154
    Answers
    8

    Default Can't access store at first start, but after 2nd start its working... Why??

    I'm loading 2 stores when starting my app the first time to init them with test-values.

    Problem is that one store is ok, but the second store I can't access at the first time. But after reloading the app, both stores work...

    I checked with developer tools: both stores have their data loaded, and for both I'm using the same mechanism, yet only 1 will be accessable at very first app start.... If I restart the app suddenly both stores are accesable and everything is fine... What am I doing wrong here ??? Is there some refresh or sth I should do on the second store so that I can access it too??

  2. #2
    Sencha User jerome76's Avatar
    Join Date
    Apr 2012
    Location
    New Jersey
    Posts
    1,149
    Answers
    132

    Default

    I can't seem to replicate this. Can you give an example in your code or on Sencha Fiddle?

  3. #3
    Sencha User
    Join Date
    May 2012
    Posts
    154
    Answers
    8

    Default

    yes :-)


    First store working:

    Code:
    Ext.define('WaermetauscherST2.store.SQLiteDBPrim', {  
      extend: 'Ext.data.Store',
      
      requires: ['WaermetauscherST2.model.Prim'],
      
      config: {
        model: 'WaermetauscherST2.model.Prim',
        autoLoad: true,
        storeId: 'SQLiteDBPrim',
        pageSize: 1000,
        listeners: {
            'load' :  {
                fn : function(store,records,options) {
                     
                    ///////////////////////////////////////////////////////////////////
                    // debug and testing initialization with test values:
                    //
                    var primstore = Ext.getStore('SQLiteDBPrim');
                    if (primstore.getCount() < 1)
                    {
                        // no data in store, lets provide some test data:
                        primstore.add({applicationId: '1', value1:'10', value2:'50'});
                        primstore.add({applicationId: '1', value1:'20', value2:'50'});
                        primstore.add({applicationId: '2', value1:'30', value2:'50'});
                        primstore.add({applicationId: '2', value1:'20', value2:'50'});
                        primstore.add({applicationId: '3', value1:'50', value2:'50'});
                        primstore.add({applicationId: '4', value1:'20', value2:'50'});
                        primstore.add({applicationId: '4', value1:'70', value2:'50'});
                        primstore.add({applicationId: '5', value1:'20', value2:'50'});
                        primstore.add({applicationId: '5', value1:'90', value2:'50'});
                        primstore.add({applicationId: '6', value1:'20', value2:'50'});
                        primstore.add({applicationId: '6', value1:'10', value2:'50'});
                        primstore.add({applicationId: '7', value1:'20', value2:'50'});
                        primstore.add({applicationId: '7', value1:'10', value2:'50'});
                        primstore.sync();
            
                    }
                },
                scope : this
            }
        }
      }
    });

    Second not working first time, only working after refreshing the browser, but the data is loaded (I checked that...). The data is just not accessible somehow... I can access the first stores data but the second store is somehow locked or sth at initial startup:


    Code:
    Ext.define('WaermetauscherST2.store.SQLiteDBSec', {  
      extend: 'Ext.data.Store',
      
      requires: ['WaermetauscherST2.model.Sec'],
      
      config: {
        model: 'WaermetauscherST2.model.Sec',
        autoLoad: true,
        storeId: 'SQLiteDBSec',
        pageSize: 1000,
        listeners: {
            'load' :  {
                fn : function(store,records,options) {
                     
                    ///////////////////////////////////////////////////////////////////
                    // debug and testing initialization with test values:
                    //
                    var secstore = Ext.getStore('SQLiteDBSec');
                    if (secstore.getCount() < 1)
                    {
                        // no data in store, lets provide some test data:
                        secstore.add({primId: '1', value1:'20', value2:'30'});
                        secstore.add({primId: '1', value1:'50', value2:'30'});
                        secstore.add({primId: '2', value1:'120', value2:'130'});
                        secstore.add({primId: '2', value1:'150', value2:'130'});
                        secstore.add({primId: '3', value1:'40', value2:'30'});
                        secstore.add({primId: '3', value1:'50', value2:'30'});
                        secstore.add({primId: '4', value1:'40', value2:'30'});
                        secstore.add({primId: '4', value1:'50', value2:'30'});
                        secstore.add({primId: '5', value1:'50', value2:'30'});
                        secstore.add({primId: '5', value1:'60', value2:'30'});
                        secstore.add({primId: '6', value1:'20', value2:'30'});
                        secstore.add({primId: '7', value1:'80', value2:'30'});
                        secstore.add({primId: '7', value1:'90', value2:'90'});
                        secstore.add({primId: '8', value1:'110', value2:'130'});
                        secstore.add({primId: '8', value1:'150', value2:'30'});
                        secstore.add({primId: '9', value1:'120', value2:'30'});
                        secstore.add({primId: '9', value1:'150', value2:'30'});
                        secstore.sync();
                    }
                },
                scope : this
            }
        }
      }
    });

  4. #4
    Sencha User
    Join Date
    Mar 2012
    Location
    Mumbai, India
    Posts
    33
    Answers
    2

    Default

    I don't understand. How exactly are you accessing your store, what mechanism you are toking about? And, Where are you supplying data to your store??? because i see no proxy or data configs used.
    Your load listener fires whenever records have been loaded into the store.

  5. #5
    Sencha User
    Join Date
    May 2012
    Posts
    154
    Answers
    8

    Default

    I'm talking about starting the app for the very first time. But not in production mode but just for me as a developer to debug it. Right now I don't have any data to load into my store, so for testing and debugging I decided to add test-data to my stores.

    So first I check if the getCount of the corresponding store is smaller than 1. This indicates, that there is no data in the store. And if that is the case, I add test-records to my store just for testing...

    It's just strange, that both stores are almost the same. Just that the first store loads ok and the second also loads ok, but I can't access the 2nd store, only after restarting the app... Its not a big deal, I guess as soon as I get real data it works immediately :-)

    And if not they will have to restart the app so that it works *joke

  6. #6
    Sencha User
    Join Date
    Mar 2012
    Location
    Mumbai, India
    Posts
    33
    Answers
    2

    Default

    ok, my concern is the function that you are using to load your test data gets executed only when the load event fires.
    Now load event fires when the data gets loaded, so according to me your function should never get executed as load event never fires in this scenario.
    I tried this and as expected the load event is not getting fired even on reloading the app.
    Code:
    Ext.define('forum.store.str', {  
      extend: 'Ext.data.Store',
      config: {
        model:'forum.model.mod',
        autoLoad: true,
        storeId: 'SQLiteDBSec',
        pageSize: 1000,
        listeners: {
            'load' :  {
                fn : function(store,records,options) {
                        alert('hi');
                }
                scope : this
           }
        }
      }
    });
    and Main.js
    Code:
    Ext.define("forum.view.Main", {
        extend: 'Ext.tab.Panel',
        requires: [
            'Ext.TitleBar',
            'Ext.Video'
        ],
        config: {
            tabBarPosition: 'bottom',
    
    
            items: [
                {
                    title: 'Welcome',
                    iconCls: 'home',
    
    
                    styleHtmlContent: true,
                    scrollable: true,
    
    
                    items: {
                        docked: 'top',
                        xtype: 'titlebar',
                        title: 'Welcome to Sencha Touch 2'
                    },
    
    
                    html: [
                        "You've just generated a new Sencha Touch 2 project. What you're looking at right now is the ",
                        "contents of <a target='_blank' href=\"app/view/Main.js\">app/view/Main.js</a> - edit that file ",
                        "and refresh to change what's rendered here."
                    ].join("")
                },
                {
                    title:'list',
                    xtype:'list',
                    store:'SQLiteDBSec'
                }
            ]
        }
    });

  7. #7
    Sencha Premium User bluehipy's Avatar
    Join Date
    Mar 2010
    Location
    Romania
    Posts
    628
    Answers
    67

    Default

    @klaus777

    You are doing some strange things in there

    If you want some test data you can specify this in your store config data, no need to put it in the load handler of the same store, that is the wired part


    Code:
    Ext.define('WaermetauscherST2.store.SQLiteDBSec', {  
      extend: 'Ext.data.Store',
      
      requires: ['WaermetauscherST2.model.Sec'],
      
      config: {
        model: 'WaermetauscherST2.model.Sec',
        autoLoad: true,
        storeId: 'SQLiteDBSec',
        data:[
                  {primId: '1', value1:'20', value2:'30'},
                  {primId: '1', value1:'20', value2:'30'},
                  {primId: '1', value1:'20', value2:'30'},
                  {primId: '1', value1:'20', value2:'30'},
                  {primId: '1', value1:'20', value2:'30'},
                  {primId: '1', value1:'20', value2:'30'}
        ]

    For the first store is working probbaly just because one of the components linked to it ask for a load and some how the load event handler gets activated.

Posting Permissions

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