Results 1 to 2 of 2

Thread: How do I apply a store to a combobox?

  1. #1
    Sencha User
    Join Date
    Aug 2011
    Posts
    120
    Answers
    4
    Vote Rating
    3
      0  

    Default Answered: How do I apply a store to a combobox?

    Code:
    {
        fieldLabel: 'Tip',
        name: 'SubjectType',
        allowBlank: false,
        xtype: 'combo',
        displayField: 'name',
        valueField: 'type',
        typeAhead: true,
        forceSelection: true,
        queryMode: 'local',
        store: subjectTypeStore,
        listeners: {
            select: function(a,selected,c){
                //console.log(a);
                var tets = selected[0].data.type;
                console.log(tets);
                //console.log(c);
            }
        }
    },
    {
        name: 'SubjectID',
        allowblank: false,
        xtype: 'combo',
        displayField: 'name',
        valuefield: 'name',
        typeAhead: true,
        forceSelection: true,
        queryMode: 'local'
    }
    What I want to do is to apply a combobox store to the second combobox according to the selected item in the first combobox. For example if you select Pokemons then the second combobox should load pokemonStore. You change your mind and you select Smurfs, then the second combobox loads the smurfsStore.

    What I want to learn is how to apply the store to an existent combobox.

  2. See if this will work for you:

    Code:
    var statesA = Ext.create('Ext.data.Store', {
        fields: ['abbr', 'name'],
        data : [
            {"abbr":"AL", "name":"Alabama"},
            {"abbr":"AK", "name":"Alaska"},
            {"abbr":"AZ", "name":"Arizona"}
        ]
    });
    
    var statesZ = Ext.create('Ext.data.Store', {
        fields: ['abbr', 'name'],
        data : [
            {"abbr":"ZL", "name":"ZAlabama"},
            {"abbr":"ZK", "name":"ZAlaska"},
            {"abbr":"ZZ", "name":"ZArizona"}
        ]
    });
    
    var comboA = Ext.create('Ext.form.ComboBox', {
        fieldLabel: 'Choose State',
        store: statesA,
        queryMode: 'local',
        displayField: 'name',
        valueField: 'abbr',
        renderTo: Ext.getBody(),
        listeners: {
            select: function(combo) {
                comboZ.bindStore(statesZ);
            }
        }
    });
    
    var comboZ = Ext.create('Ext.form.ComboBox', {
        fieldLabel: 'Choose State',
        store: null,
        queryMode: 'local',
        displayField: 'name',
        valueField: 'abbr',
        renderTo: Ext.getBody()
    });
    Scott.

  3. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,388
    Answers
    716
    Vote Rating
    499
      1  

    Default

    See if this will work for you:

    Code:
    var statesA = Ext.create('Ext.data.Store', {
        fields: ['abbr', 'name'],
        data : [
            {"abbr":"AL", "name":"Alabama"},
            {"abbr":"AK", "name":"Alaska"},
            {"abbr":"AZ", "name":"Arizona"}
        ]
    });
    
    var statesZ = Ext.create('Ext.data.Store', {
        fields: ['abbr', 'name'],
        data : [
            {"abbr":"ZL", "name":"ZAlabama"},
            {"abbr":"ZK", "name":"ZAlaska"},
            {"abbr":"ZZ", "name":"ZArizona"}
        ]
    });
    
    var comboA = Ext.create('Ext.form.ComboBox', {
        fieldLabel: 'Choose State',
        store: statesA,
        queryMode: 'local',
        displayField: 'name',
        valueField: 'abbr',
        renderTo: Ext.getBody(),
        listeners: {
            select: function(combo) {
                comboZ.bindStore(statesZ);
            }
        }
    });
    
    var comboZ = Ext.create('Ext.form.ComboBox', {
        fieldLabel: 'Choose State',
        store: null,
        queryMode: 'local',
        displayField: 'name',
        valueField: 'abbr',
        renderTo: Ext.getBody()
    });
    Scott.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •