dowjones123
dowjones123

Reputation: 3837

Ext.getStore() creating error: Uncaught TypeError: undefined is not a function

I am creating a ListView and populating it with some data from a store that I have created.

When I am assigning the store to the listview using store : Ext.getStore('Feeds'), I get an error :

Uncaught TypeError: undefined is not a function

View class:

Ext.define('Volt.view.FeedView', {
    extend: 'Ext.Panel',

    requires: [
        'Ext.TitleBar',
        'Ext.Button',
        'Ext.Toolbar'
        //'Ext.Panel'
    ],

    xtype: 'feedViewCard',

    config: {
        iconCls: 'action',
        title: 'FeedView',
        layout: {
            type: 'vbox'
        },
        items: [
            {
                xtype: 'feedlistview', // this is defined as a class that inherits from xtype = list
                store: Ext.getStore('Feeds'), //removing this line gives no error
                flex: 1,
                    }
                }
            }
        ]
    },
});

Stores class

Ext.define("Volt.store.Feeds", {
    extend: "Ext.data.Store",
    requires: "Ext.data.proxy.LocalStorage",
    config: {
        model: "Volt.model.Feed",
        data: [
            { title: "Feed 1", narrative: "narrative 1" },
            { title: "Note 2", narrative: "narrative 2" },
            { title: "Note 3", narrative: "narrative 3" },
            { title: "Note 4", narrative: "narrative 4" },
            { title: "Note 5", narrative: "narrative 5" },
            { title: "Note 6", narrative: "narrative 6" }
        ],
        sorters:[
            {
                property: 'dateCreated',
                direction: 'DESC'
            }
        ]
    }
});

Model Class

Ext.define("Volt.model.Feed", {
    extend: "Ext.data.Model",
    config: {
        idProperty: 'id',
        fields: [
            { name: 'id', type: 'int' },
            { name: 'dateCreated', type: 'date', dateFormat: 'c' },
            { name: 'title', type: 'string' },
            { name: 'narrative', type: 'string' }
        ],
        validations: [
            { type: 'presence', field: 'id'},
            { type: 'presence', field: 'dateCreated'},
            { type: 'presence', field: 'title', 'message': 'Enter a valid title'}
        ]
    }
});

Upvotes: 0

Views: 5446

Answers (1)

Saki
Saki

Reputation: 5856

You are trying to get the store during definition time when it does not yet exist. If Feeds store is listed in stores:[] of the Application or a Controller then just set it to text store:'Feeds'.

When app initializes it detects that store is a string and calls Ext.getStore for you.

You may be also interested in Ext Component Life Cycle and/or Ext Application Startup Sequence

Upvotes: 1

Related Questions