2012-10-18 21 views
0

我剛剛開始使用Extjs 4,我需要獲取選擇的組合框的值來更改商店並渲染與每個商店的數據對應的圖表。Extjs 4捕捉按鈕單擊中的組合框選定的值

我使用MVC模式,這是我的看法含有組合框:

Ext.define('Metrics.view.Params', { 
extend: 'Ext.grid.Panel', 
alias: 'widget.params', 

title: 'Select Parameters', 
hideHeaders: true, 

initComponent: function() { 
    this.columns = [{ 
     dataIndex: 'name', 
     flex: 1 
    }]; 

    this.dockedItems = [{ 
     xtype: 'container', 
     items: [{ 
        xtype: 'combobox', 
     id : 'cmbGraph', 
     mode : 'queryMode', 
        name : 'graph', 
        fieldLabel: 'Graph', 
     store: ['Small data','Big data'], 
     editable : false 
       }, 
       { 
        //another combobox here.. 

        }] 

我的控制器:

Ext.define('Metrics.controller.RenderGraph', { 
extend: 'Ext.app.Controller', 

refs: [{ 
    ref : 'params', 
    selector : 'params' 

}], 

stores: ['GraphData'], 

init: function() { 
    // Start listening for events on views 
    this.control({ 
     'paramsbtn button[action=apply]': { 
     click : this.launchChart 
     } 
    }); 

launchChart : function(button){ 
    var params = this.getParams(); 
    var combo1 = params.items[cmbGraph]; 
    console.log(Ext.encode(combo1)); 
    var v = combo1.getValue(); 
    var r = combo1.findRecord(combo1.valueField || combo1.displayField,v); 
    return(combo1.store.indexOf(r)); 
    console.log('combo item' + r + 'selected'); 
} 

正如你所看到的,我想獲得的價值的ID = cmbGraph的組合框,但它不工作,我得到的錯誤消息是:

Uncaught TypeError: Cannot call method 'getValue' of undefined 

它是與Extjs 4複雜,因爲我必須使用控制器訪問視圖元素。 任何幫助將不勝感激。

+0

發現的解決方案: 我用參數面板的 「向下」 的方法: launchChart:)功能(按鍵){ \t \t變種PARAMS = this.getParams(; \t \t var combo1 = params.down('combobox'); \t \t var mycombo = combo1.cmbGraph; \t \t console.log(Ext.encode(mycombo)); \t \t var v = combo1.getValue(); \t \t console.log(Ext.encode(v)); \t \t} – salamey

回答

0

你還可以保存裁判所以你可以,如果你需要重複使用它們,並使用這樣的事情,如果你想:

refs: [{ 
    ref : 'graph', 
    selector : 'params > container > combobox' 
}], 

refs: [{ 
    ref : 'graph', 
    selector : 'params #cmbGraph' 
}], 

或直連:

refs: [{ 
    ref : 'graph', 
    selector : '#cmbGraph' 
}], 

這些都應該給你相同的參考組合框。取決於你如何安排你的代碼。

var comboValue = me.getGraph().getValue();