1. #1
    Sencha User
    Join Date
    Nov 2011
    Posts
    3
    Vote Rating
    0
    velasquez76 is on a distinguished road

      0  

    Question Answered: Error while defining a store

    Answered: Error while defining a store


    I'm trying to create a simple list with a store in a tab panel and this is the code I did.

    Code:
    Ext.define('myApp.model.Test', {
        extend: 'Ext.data.Model',
        fields: ['id', 'title', 'cls']
    });
    
    Ext.define('myApp.store.Test', {
        extend: 'Ext.data.Store',
        config: {
            model: 'myApp.model.Test',
            sorters: 'title',
            getGroupString: function(record) {
                return record.get('title')[0];
            },
            proxy: {
                type: 'memory',
                reader: {
                    type: 'json',
                    root: 'menu'
                }
            },
            data : {
                menu: [{
                    id: 1,
                    title: 'Element 1',
                    cls: 'clsOne'
                },{
                    id: 2,
                    title: 'Element 2',
                    cls: 'clsTwo'
                }]
            }
        }
    });
    
    Ext.define('myApp.view.Main', {
        extend: 'Ext.TabPanel',
        config: {
            fullscreen: true,
            tabBarPosition: 'bottom',
            items: [
                {
                    xtype: 'list',
                    title: 'Home',
                    grouped: true,
                    indexBar: true,
                    iconCls: 'star',
                    itemTpl: '{title}',
                    store: Ext.create("myApp.store.Test")
                }            
            ]
        }
    });
    
    Ext.application({
        name: 'myApp',
        launch: function() {
            var mainPanel = Ext.create('myApp.view.Main').setActiveItem(0);
        }
    });
    The problem is that I get this error: c.model.getProxy si undefined

    I tried to set the proxy in 'myApp.model.Test' class I created too but nothing worked.

    If I create an inline instance of Ext.data.Store with the same code of 'myApp.store.Test' class it works but when I define a class extending a store and I try to create an instance of it, this error always appears.

    What did I do wrong?

  2. Hi valasquez.
    Seems that the "config" object is not actually accepted inside a store definition.
    If you put all your store configuration outside the config object everything works fine.

    Take a look at the code below:
    Code:
    Ext.require(['Ext.*']);
    
    
    Ext.application({
        name: 'myApp',
        launch: function() {
    	
    		var data = {
    			menu: [
    				{
    	                id: 1,
    	                title: 'Element 2',
    	                cls: 'clsOne'
    	            },
    				{
    	                id: 2,
    	                title: 'Element 1',
    	                cls: 'clsTwo'
    	            }
    			]
    		};
            
    		Ext.define('myApp.model.Test', {
    		    extend: 'Ext.data.Model',
    		    fields: ['id', 'title', 'cls']
    		});
    
    
    
    
    		Ext.define('myApp.store.Test', {
    		    extend: 'Ext.data.Store',
    			model: 'myApp.model.Test',
    			sorters: 'title',
    			proxy: {
    	            type: 'memory',
    	            reader: {
    	                type: 'json',
    	                root: 'menu'
    	            }
    	        },
    			data: data,
    			getGroupString: function(record) {
    	            return record.get('title')[0];
    	        }
    		});
    
    
    		Ext.define('myApp.view.Main', {
    		    extend: 'Ext.TabPanel',
    		    config: {
    		        fullscreen: true,
    		        tabBarPosition: 'bottom',
    		        items: [
    		            {
    		                xtype: 'list',
    		                title: 'Home',
    		                grouped: true,
    		                indexBar: true,
    		                iconCls: 'star',
    		                itemTpl: '{title}',
    		                store: Ext.create("myApp.store.Test")
    		            }            
    		        ]
    		    }
    		});
    
    
    		var mainPanel = Ext.create('myApp.view.Main').setActiveItem(0);
        }
    });
    Hope this helps.

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

      0  

    Default


    Hi valasquez.
    Seems that the "config" object is not actually accepted inside a store definition.
    If you put all your store configuration outside the config object everything works fine.

    Take a look at the code below:
    Code:
    Ext.require(['Ext.*']);
    
    
    Ext.application({
        name: 'myApp',
        launch: function() {
    	
    		var data = {
    			menu: [
    				{
    	                id: 1,
    	                title: 'Element 2',
    	                cls: 'clsOne'
    	            },
    				{
    	                id: 2,
    	                title: 'Element 1',
    	                cls: 'clsTwo'
    	            }
    			]
    		};
            
    		Ext.define('myApp.model.Test', {
    		    extend: 'Ext.data.Model',
    		    fields: ['id', 'title', 'cls']
    		});
    
    
    
    
    		Ext.define('myApp.store.Test', {
    		    extend: 'Ext.data.Store',
    			model: 'myApp.model.Test',
    			sorters: 'title',
    			proxy: {
    	            type: 'memory',
    	            reader: {
    	                type: 'json',
    	                root: 'menu'
    	            }
    	        },
    			data: data,
    			getGroupString: function(record) {
    	            return record.get('title')[0];
    	        }
    		});
    
    
    		Ext.define('myApp.view.Main', {
    		    extend: 'Ext.TabPanel',
    		    config: {
    		        fullscreen: true,
    		        tabBarPosition: 'bottom',
    		        items: [
    		            {
    		                xtype: 'list',
    		                title: 'Home',
    		                grouped: true,
    		                indexBar: true,
    		                iconCls: 'star',
    		                itemTpl: '{title}',
    		                store: Ext.create("myApp.store.Test")
    		            }            
    		        ]
    		    }
    		});
    
    
    		var mainPanel = Ext.create('myApp.view.Main').setActiveItem(0);
        }
    });
    Hope this helps.
    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


  4. #3
    Sencha - Sencha Touch Dev Team rdougan's Avatar
    Join Date
    Oct 2008
    Posts
    1,158
    Answers
    93
    Vote Rating
    6
    rdougan will become famous soon enough

      0  

    Default


    @andreacammarata is correct. Unfortunately in DP1, the whole Data package (Ext.data.*) is not converted over to the configuration system.

Thread Participants: 2

Tags for this Thread