View Reference in Controller EXTJS 4

会有一股神秘感。 提交于 2019-12-23 09:38:53

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/17464392/view-reference-in-controller-extjs-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!