View Reference in Controller EXTJS 4
Asked Answered
M

1

6

I am not able to get combobox value in a controller. The getter method of combobox view returns

function i(){
    return this.constructor.apply(this,arguments)||null
} 

instead of view object instance. If I use

var combo=this.getColumnTypeComboView().create()

then I don't get selected value of the combobox combo.getValue().

Meridithmeriel answered 4/7, 2013 at 7:35 Comment(0)
T
5

To get view reference in a controller simply use getView() method from the Controller class. To create a connection between view and a controller make sure that you follow MVC aplication architecture principals, found here

var view = this.getView('Contact'); //=> getView( name ) : Ext.Base

if a combobox is a item of a view that your controller is in charge off, then use control method also from Controller class.

Ext.define('My.controller.Contact', {
    extend: 'Ext.app.Controller',
    views: ['Contact'],
    init: function() {

        //reference the view
        var view = this.getView('Contact');

        //reference the combobox change event
        this.control({
            'mywin combobox': {
                 change: this.onChangeContinent
            }
        });

    },
    onChangeContinent:function (field, value, options) {

        //here you can get combobox component and its value
        Ext.Msg.alert('Continent', value);
    }
});

here is a fiddle example

EDIT:

To reference one component from another, you can use Controller ref method, like this:

refs: [{
    ref: 'combo',
    selector: 'mywin combobox'
}]

here is a fiddle example 2

Transformer answered 4/7, 2013 at 8:41 Comment(3)
Thanks for your response. Can you please let me know, how do we get the selected value of the combobox in the controller on click of save button in this fiddle example..Meridithmeriel
Thanks Devor. I was using getComboView, instead of getCombo.Meridithmeriel
the getter method is generated using 'ref' value get + ref value (combo) = getCombo(). Cheers!Transformer

© 2022 - 2024 — McMap. All rights reserved.