Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View Reference in Controller EXTJS 4

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().

like image 493
Rakesh Goyal Avatar asked Jul 04 '13 07:07

Rakesh Goyal


1 Answers

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

like image 124
Davor Zubak Avatar answered Sep 25 '22 15:09

Davor Zubak