Results 1 to 3 of 3

Thread: Is there a way to list all stores?

  1. #1
    Sencha User
    Join Date
    Jun 2017
    Posts
    25
    Answers
    1

    Default Is there a way to list all stores?

    I'm just looking for a way to get a list of all stores. Like a component query, but for stores. Some of these stores may not be registered with the store manager, as no storeId was given. I can see a bunch of stores with Sencha Inspector, but I need to manipulate these programatically.

    I saw this thread, which mentions 'Ext.app.getStores()', but this is giving me 'not a function'.
    https://www.sencha.com/forum/showthr...an-application

    Halp.

  2. #2
    Sencha Premium Member richardvd's Avatar
    Join Date
    Jun 2011
    Location
    NL
    Posts
    253
    Answers
    22

    Default

    The Ext.data.StoreManager holds the collection of registered store items. You can walk through each store like this:

    Code:
    Ext.data.StoreManager.each( function(store) {
      console.log(store.id);
    });

  3. #3
    Sencha User yeghikyan's Avatar
    Join Date
    Mar 2009
    Location
    München
    Posts
    574
    Answers
    99

    Default

    There are several ways to achieve this goal:

    First: You can use this override to register stores in some global variable. Here you will have to manage the remove of store from this variable after the component is destroyed to avoid the memory leaks.

    Code:
    STORES = {};
    Ext.define('overrides.data.AbstractStore', {
        override: 'Ext.data.AbstractStore',
    
    
        constructor: function (config) {
            this.callParent([config]);
            STORES[this.getId()] = this;
        }
    });
    Second: You can set the 'storeId' if it is not set with an unique id of the store and then iterate as it was said by Richard:

    Code:
    Ext.define('overrides.data.AbstractStore', {
        override: 'Ext.data.AbstractStore',
    
    
        constructor: function (config) {
            if(!this.storeId) {
                this.storeId = this.getId();
            }
            this.callParent([config]);
        }
    });
    
    // iteration function.
    
    Ext.data.StoreManager.each( function(store) {
      if(store) {
        console.log(store.storeId, store.getRange());
      }
    });
    Or you can... I think this two tricks are enough. I personally would like to use the second one, to avoid memory leak and global variable.
    "The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague." – Edsger W. Dijkstra

Similar Threads

  1. List data from two stores
    By mpkuif24 in forum Sencha Architect 2.x: Help & Discussions
    Replies: 0
    Last Post: 8 May 2014, 9:06 AM
  2. One list multiple stores
    By InspectaRoger in forum Sencha Architect 2.x: Help & Discussions
    Replies: 3
    Last Post: 13 May 2013, 8:10 AM
  3. List with 2 stores
    By ci11111 in forum Sencha Touch 2.x: Q&A
    Replies: 18
    Last Post: 19 Apr 2012, 5:17 AM
  4. Multiple Stores in a List
    By TDDV in forum Sencha Touch 1.x: Q&A
    Replies: 2
    Last Post: 13 Feb 2012, 8:01 AM

Posting Permissions

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