combobox load

by el_chief

HTML

<link rel="stylesheet" href="//extjs.cachefly.net/ext-4.1.0-gpl/resources/css/ext-all-gray-debug.css" />
<script src="//extjs.cachefly.net/ext-4.1.0-gpl/ext-all-dev.js"></script>

JavaScript

function sim(proxy, data, delay) {
    if (typeof data !== 'string') {
        data = Ext.JSON.encode(data);
    }

    proxy.url = '/echo/json/';
    proxy.actionMethods.read = "POST";
    proxy.extraParams.json = data;
    proxy.extraParams.delay = typeof delay == 'undefined' ? 0 : delay;
}


Ext.define('Model1', {
    extend: 'Ext.data.Model',
    fields: ['id', 'text'],
    proxy: {
        type: 'ajax',
        url: '/echo/json/',
        reader: {
            type: 'json'
        }
    }
});

sim(Model1.proxy, [{
    id: 1,
    text: 'a'},
{
    id: 2,
    text: 'neil is ossom'}], 1);

Ext.define('Store1', {
    extend: 'Ext.data.Store',
    model: 'Model1',
    autoLoad: false
});

Ext.define('Form1', {
    extend: 'Ext.form.Panel',

    height: 250,
    width: 490,
    bodyPadding: 10,
    title: 'My Form',

    initComponent: function() {
        var me = this;

        Ext.applyIf(me, {
            items: [
                {
                xtype: 'combobox',
                fieldLabel: 'Label',
                    width:350,
                    pageSize:true,
                store: new Store1(),
                valueField: 'id',
                displayField: 'text'}
            ]
        });

        me.callParent(arguments);
    }
});

var f = new Form1({
    renderTo: Ext.getBody()
});

var c = f.down('combobox');
c.store.add({
    id: 2,
    text: 'neil'
});
c.setValue(2);
console.log(c.store);