问题
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