Sencha Touch store examples (showing model, proxy, JSON, REST, static fields)

The following Sencha Touch code shows how to define a Store, where the store references a model, has a proxy, and also uses some configuration parameters to help control the REST/GET URL/URI the store generates:

Ext.define('RadioMobile.store.RadioStreams', {
    extend: 'Ext.data.Store',
    requires: 'RadioMobile.model.RadioStream',

    config: {
        model: 'RadioMobile.model.RadioStream',
        proxy: {
            type: 'ajax',
            url: '/server/getRadioStreams',
            method: 'GET',
            reader: {
                type: 'json'
                //root: 'results'
            },
            // get these variables out of the GET url
            noCache: false,
            limitParam: undefined,
            pageParam: undefined,
            startParam: undefined,
        }
    }

});

The model this store references is very simple:

Ext.define('RadioMobile.model.RadioStream', {
    extend: 'Ext.data.Model',

    config: {
	    fields: [
	        { name: 'name' }
	    ]
    }

});

The following store kinda-sorta shows that you can define fields directly in the store, instead of needing a model. That can be useful when prototyping or using static data:

Ext.define('RadioMobile.store.Podcasts', {
    extend: 'Ext.data.Store',

    // fields: [
    //     {name: 'filename'}
    // ],

    requires: 'RadioMobile.model.Podcast',

    config: {
        model: 'RadioMobile.model.Podcast',

        proxy: {
            type: 'ajax',
            url: '/server/getPodcasts',
            method: 'GET',
            reader: {
                type: 'json'
            },
            noCache: true,
            limitParam: undefined,
            pageParam: undefined,
            startParam: undefined
        },
    }

});

Add new comment

The content of this field is kept private and will not be shown publicly.

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.