0
votes

Using the example in "ext-designer-for-ext-js-4-users-guide.pdf" i've put together the following. The issue is that the store is not binding. ie the select is empty.

MyComboBox.js

Ext.define('MyApp.view.MyComboBox', {
    extend: 'MyApp.view.ui.MyComboBox',

    initComponent: function() {
        var me = this;
        me.callParent(arguments);
    }
});

Ext.define('MyApp.view.ui.MyComboBox', {
    extend: 'Ext.form.field.ComboBox',

    fieldLabel: 'comboList',
    displayField: 'comboList',
    queryMode: 'local',
    store: 'MyArrayStore',
    triggerAction: 'all',
    valueField: 'comboList',

    initComponent: function() {
        var me = this;

        me.callParent(arguments);
    }
});

store/MyArrayStore.js

  Ext.define('MyApp.store.MyArrayStore', {
    extend: 'Ext.data.Store',

    constructor: function(cfg) {
        var me = this;
        cfg = cfg || {};
        me.callParent([Ext.apply({
            autoLoad: true,
            storeId: 'MyArrayStore',
            data: [
                [
                    'Search Engine'
                ],
                [
                    'Online Ad'
                ],
                [
                    'Facebook'
                ]
            ],
            proxy: {
                type: 'ajax',
                reader: {
                    type: 'array'
                }
            },
            fields: [
                {
                    name: 'comboList'
                }
            ]
        }, cfg)]);
    }
});

** update **

this was driving me crazy. It's [turns out][1] my array need to be json format. When i updated it to

[{"comboList" : "Hello"}, {"comboList" : "Hi"}, {"comboList" : "GoodMorning"}]

it worked.

1

1 Answers

1
votes

I started to try and pick apart your implementation but it seems somewhat convoluted, starting with the store where there is local data and a proxy defined but no url for the proxy.

It seemed easier to just give you a simplified implementation of a combobox (using local data because it seems that is what you are trying to do):

// the datastore
var myStore = Ext.create('Ext.data.Store', {
    fields: ['value', 'name'],
    data: [
        {value: 1, name: 'Search Engine'},
        {value: 2, name: 'Online Ad'},
        {value: 3, name: 'Facebook'}
    ]
});    

// a window to hold the combobox inside of a form 
myWindow = Ext.create('Ext.Window', {
    title: 'A Simple Window',
    width: 300,
    constrain: true,
    modal: true,
    layout: 'fit',
    items: [{
        // the form to hold the combobox
        xtype: 'form',
        border: false,
        fieldDefaults: {
            labelWidth: 75
        },
        bodyPadding: '15 10 10 10',
        items: [{
            // the combobox
            xtype: 'combo',
            id: 'myCombo',
            fieldLabel: 'Title',
            valueField: 'value',
            displayField: 'name',
            store: myStore,
            queryMode: 'local',
            typeAhead: true,
            forceSelection: true,
            allowBlank: false,
            anchor: '100%'
        },{
            // shows the selected value when pressed
            xtype: 'button',
            margin: '10 0 0 100',
            text: 'OK',
            handler: function() {
                alert('Name: ' + Ext.getCmp('myCombo').getRawValue() + 
                      '\nValue: ' + Ext.getCmp('myCombo').value);
            }
        }]
    }]
});
// show the window
myWindow.show();   

This creates a combobox inside of a little window with an OK button. When you press OK it will alert the visible text of the combobox Ext.getCmp('myCombo').getRawValue() and the value of the item in the combobox Ext.getCmp('myCombo').value.

If you drop this in your project you can get an idea of how it implements, it should just run.

If you actually wanted a remote datastore (from a webservice that returns json for example) you would just need to change the datastore configuration like so:

var myRemoteStore = Ext.create('Ext.data.Store', {
    fields: ['value', 'name'],
    proxy: {
        type: 'ajax', 
        url: 'myWebservice.php', // whatever your webservice path is
        reader: 'json',
    },
    autoLoad:true  
});