查看控制器EXTJS 4中的参考

Rak*_*yal 6 extjs4 extjs-mvc extjs4.2

我无法在控制器中获得组合框值.组合框视图的getter方法返回

function i(){
    return this.constructor.apply(this,arguments)||null
} 
Run Code Online (Sandbox Code Playgroud)

而不是查看对象实例.如果我使用

var combo=this.getColumnTypeComboView().create()
Run Code Online (Sandbox Code Playgroud)

然后我没有得到组合框的选定值combo.getValue().

Dav*_*bak 5

要获取控制器中的视图引用,只需使用Controller 类中的getView()方法。要在视图和控制器之间创建连接,请确保遵循 MVC 应用程序架构原则(可在此处找到)

var view = this.getView('Contact'); //=> getView( name ) : Ext.Base
Run Code Online (Sandbox Code Playgroud)

如果组合框是控制器负责的视图的项目,则也使用 Controller 类中的控制方法。

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);
    }
});
Run Code Online (Sandbox Code Playgroud)

这是一个小提琴示例

编辑:

要从一个组件引用另一个组件,您可以使用 Controller ref方法,如下所示:

refs: [{
    ref: 'combo',
    selector: 'mywin combobox'
}]
Run Code Online (Sandbox Code Playgroud)

这是一个小提琴示例2