1. #1
    Sencha User
    Join Date
    Sep 2011
    Location
    Sallanches, France
    Posts
    371
    Vote Rating
    1
    myput is on a distinguished road

      0  

    Default Dynamic Store

    Dynamic Store


    hello,

    I would like to know how to load a dynamic store by ID.
    I Explain:

    I have a list, my model contain each ID for each Items.
    I would like to load a different Store by different Items of the list.

    I saw we can load a store dynamically, but i don't know how to do that, it doesn't work.

    I have my List and the Store in my BaseList:
    Code:
    Ext.regModel('WPApp.models.DirectoryBaseListModel', {
    	fields: [
    		{name: 'ID', type: 'int'},    
    		{name: 'NAME', type: 'string'}
    	]
    });
    
    
    WPApp.stores.DirectoryBaseListStore = new Ext.data.Store({
    	model: "WPApp.models.DirectoryBaseListModel",
    	proxy: {
    		type: 'ajax',
    		url: 'http://localhost:8888/WPApp/data/BaseList.json',
    		reader: {
    			type: 'json'
    		}               
    	},
    	autoLoad: true
    });
    
    
    WPApp.views.DirectoryBaseListPanelToolbar = new Ext.Toolbar ({
    	title: 'Annuaire WeshProd',
    	id: 'DirectoryBasePanelToolbar',
    	dock: 'top',
    	layout: {
            pack: 'center'
        }
    });
    
    
    WPApp.views.DirectoryBaseListPanel = Ext.extend(Ext.Panel,{
    	id: 'DirectoryBaseListPanel',
    	dockedItems: [WPApp.views.DirectoryBaseListPanelToolbar],
    	items: [{
    		xtype: 'list',
    		store: WPApp.stores.DirectoryBaseListStore,
    		itemTpl: loadURL('http://localhost:8888/WPApp/app/views/ModuleDirectory/templates/DirectoryBaseListPanel.html'),
    		onItemDisclosure: function(record) {
    			Ext.dispatch({
    				controller: WPApp.controllers.DirectoryController,
    				action: 'showDirectoryCategoryList',
    				id: record.data.ID,
    				name: record.data.NAME
    			});
    		}
    	}]
    });
    In my CategoryList i have:
    Code:
    Ext.regModel('WPApp.models.DirectoryCategoryListModel', {
    	fields: [
    		{name: 'ID', type: 'int'},    
    		{name: 'NAME', type: 'string'}
    	]
    });
    
    
    WPApp.stores.DirectoryCategoryListStore = new Ext.data.Store({
    	model: "WPApp.models.DirectoryCategoryListModel",
    	proxy: {
    		type: 'ajax',
    		url: 'http://localhost:8888/WPApp/data/RestaurantList.json',
    		reader: {
    			type: 'json'
    		}
    	},
    	autoLoad: true
    });
    
    
    WPApp.views.DirectoryCategoryListPanelToolbar = new Ext.Toolbar ({
    	title: 'Categories',
    	id: 'DirectoryCategoryPanelToolbar',
    	dock: 'top',
    	items: [{
    		xtype: 'button',
    		text: 'Categories',
    		ui: 'back',
    		handler: function() {
    			Ext.dispatch({
    				controller: WPApp.controllers.DirectoryController,
    				action: 'backToDirectoryBaseList'
    			});
    		},
    		scope: this
    	}]
    });
    
    
    WPApp.views.DirectoryCategoryListPanel = Ext.extend(Ext.Panel,{
        id: "DirectoryCategoryListPanel",
    	dockedItems: [WPApp.views.DirectoryCategoryListPanelToolbar],
    	items: [{
    		xtype: 'list',
    		store: WPApp.stores.DirectoryCategoryListStore,
    		itemTpl: loadURL('http://localhost:8888/WPApp/app/views/ModuleDirectory/templates/DirectoryCategoryListPanel.html'),
    	}]
    });
    And i would like change the url of the Store, i would like load a store with the ID i get in the ListBase.

    The function of my controller is:
    Code:
    	showDirectoryCategoryList: function(options) {
    		var id = parseInt(options.id);
    		var name = options.name;
    		WPApp.stores.DirectoryCategoryListStore.getProxy().extraParams.ID = id;
    		WPApp.stores.DirectoryCategoryListStore.read();
    		WPApp.views.DirectoryCategoryListPanelToolbar.setTitle(name);
    		WPApp.views.DirectoryPanel.setActiveItem(
    			WPApp.views.DirectoryCategoryListPanel, options.animation
    		);
    	},
    But i think it's false,
    i tested some things but no success ....

    Need help please

  2. #2
    Sencha - Services Team AndreaCammarata's Avatar
    Join Date
    Jun 2009
    Posts
    1,395
    Vote Rating
    23
    AndreaCammarata has a spectacular aura about AndreaCammarata has a spectacular aura about

      0  

    Default


    Hi myput.
    I think I don't really understand what you are trying to do.
    Just a question:
    You say that you want to load different Store according to your list disclosure event but telling this do you mean that your application has many stores and you want to load the right one or that you want to reload a single store to retrive different data according to the selected item ID?
    Sencha Inc
    Andrea Cammarata, Solutions Engineer
    Owner at SIMACS

    @AndreaCammarata
    www.andreacammarata.com
    github: https://github.com/AndreaCammarata

    TUX components bundle for Sencha Touch 2.x.x
    https://github.com/AndreaCammarata/TUX


  3. #3
    Sencha User
    Join Date
    Sep 2011
    Location
    Sallanches, France
    Posts
    371
    Vote Rating
    1
    myput is on a distinguished road

      0  

    Default


    Hum, yes i want to load a different Json file for the different ID in my list disclosure event. i don't want one Store. When i click on an item list, i would like to load the good Json file, not a big Json file who contain all items sub list cause i have some list in list, and it's lighter to load just the good light json file

    In fact, i Explain since the begening:
    I have my main view, who contain a list.
    -- thing 1
    -- thing 2
    -- thing 3
    in my Json: just item: 1,2,3

    When i click on thing 2 for exemple,
    i open a list view again, who have
    -- thing A
    -- thing B
    -- thing C
    and with a Json just item: A,B,C
    Etc ...
    And the list load in real time the good Json

    Have you an idea?

  4. #4
    Sencha - Services Team AndreaCammarata's Avatar
    Join Date
    Jun 2009
    Posts
    1,395
    Vote Rating
    23
    AndreaCammarata has a spectacular aura about AndreaCammarata has a spectacular aura about

      0  

    Default


    One possibility to do that would be to register your stores with (for example)

    Code:
    Ext.regStore('Thing2', { 
        model: '<YOUR MODEL>' 
    });
    And then on your item disclosure event

    Code:
    showDirectoryCategoryList: function(options) {
        var name = options.name;
        var store = Ext.getStore('Thing' + options.id);
        store.read();
        WPApp.views.DirectoryCategoryListPanelToolbar.setTitle(name);
        WPApp.views.DirectoryPanel.setActiveItem(
            WPApp.views.DirectoryCategoryListPanel, options.animation
        );
    },
    Sencha Inc
    Andrea Cammarata, Solutions Engineer
    Owner at SIMACS

    @AndreaCammarata
    www.andreacammarata.com
    github: https://github.com/AndreaCammarata

    TUX components bundle for Sencha Touch 2.x.x
    https://github.com/AndreaCammarata/TUX


  5. #5
    Sencha User
    Join Date
    Sep 2011
    Location
    Sallanches, France
    Posts
    371
    Vote Rating
    1
    myput is on a distinguished road

      0  

    Default


    Hum oki, thanks.
    I have just a problem and a question:
    in my second list:
    Code:
    WPApp.views.DirectoryCategoryListPanel = Ext.extend(Ext.Panel,{
        id: "DirectoryCategoryListPanel",
    	dockedItems: [WPApp.views.DirectoryCategoryListPanelToolbar],
    	items: [{
    		xtype: 'list',
    		store: WPApp.stores.DirectoryCategoryListStore[option.id],
    		itemTpl: loadURL('http://localhost:8888/WPApp/app/views/ModuleDirectory/templates/DirectoryCategoryListPanel.html'),
    	}]
    });
    What i write in the store place then?


    Another question , can i have One store, and put for example:
    Code:
    Ext.regStore('DirectoryCategoryListStore', {
    	model: "WPApp.models.DirectoryCategoryListModel",
    	proxy: {
    		type: 'ajax',
    		url: 'http://localhost:8888/WPApp/data/thing?id=1.json',
    		reader: {
    			type: 'json'
    		}
    	},
    	autoLoad: true
    });
    Juste one store who get the ID and have the url dynamic?

  6. #6
    Sencha User
    Join Date
    Aug 2011
    Location
    London
    Posts
    409
    Vote Rating
    18
    digeridoopoo will become famous soon enough

      0  

    Default I have the same problem...

    I have the same problem...


    Hey, I have the same problem. Did you have any progress? I have 36 items in my list and wanted it to dynamically load a different store number for each one instead of declaring 36 stores!

    I have an ID declared for each item in my list, but I am stuck at being able to pass this ID number to my store when clicking the item.

    I am also wondering, if this will be the best way to do it. Will Sencha be able to update/reload the store quick enough before launching my popup window?

    Someone else said they solved it by removing the URL from the store and setting the auto load to false:

    Code:
    store.getProxy().url = './getnotes?folderName=' + folderName;
    store.load();


    This is what I tried as a basic test, but I get the error 'Uncaught Error: You are using a ServerProxy but have not supplied it with a url'.

    Code:
    var store = new Ext.data.Store({
            model: 'One',
            autoload: false,
            proxy: {
                type: 'ajax',
                reader: {
                    type: 'json',
                    root: 'albums'
                }
            },
            listeners: {
                single: true,
                datachanged: function(){
                    Ext.getBody().unmask();
    
    
        store.getProxy().url = 'http://localhost/sicarousel/Carousel 2_files/get-album2.php';
        store.load();