0
votes

I have the following Model that uses a proxy to retrieve JSON from a URL via AJAX.

Ext.define('RateManagement.model.Currency', {
    extend: 'Ext.data.Model',

    fields: [
        { name: 'id', type: 'string' },
        { name: 'name', type: 'string' },
        { name: 'code', type: 'string' }
    ],

    proxy: {
        type: 'ajax',
        url: 'currencies.json'
    }

});

How can I change this to use static, hardcoded values instead of database driven values?

I have been looking at the doc http://docs.sencha.com/extjs/4.0.7/#!/api/Ext.data.Model and I came across Raw but I am not sure how to use it or it if it the correct property.

2

2 Answers

1
votes

Something like:

var store = new Ext.data.Store({
    model: 'RateManagement.model.Currency',
    data: [{
        id: 1,
        name: 'Foo',
        code: 'abc'
    }]
});
1
votes

You can use a memory proxy for your model:

Ext.define('RateManagement.model.Currency', {
    extend: 'Ext.data.Model',

    fields: [
        { name: 'id', type: 'string' },
        { name: 'name', type: 'string' },
        { name: 'code', type: 'string' }
    ],

    proxy: {
        type: 'memory',
        reader: 'json',
        data: [
            {id: 1, name: 'Foo', code: 'foo'},
            {id: 2, name: 'Bar', code: 'bar'},
            {id: 3, name: 'Baz', code: 'baz'}
        ]
    }
});