簡體   English   中英

Extjs 4在按鈕單擊中捕獲組合框選擇的值

[英]Extjs 4 catching combobox selected value in button click

我只是從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使其變得復雜,因為我必須使用控制器來訪問視圖的元素。 任何幫助將非常感激。

您還可以保留ref,以便在需要時可以重復使用它們,並在需要時使用類似的方法:

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

要么

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

甚至是直線:

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

這些都應該為您提供對組合框的相同引用。 只取決於您如何安排代碼。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM