2013-10-11 178 views
1

我已經設置了一個複選框和一個組合框,我試圖設置一個功能 - 當用戶選中複選框時,組合框必須出現。我是extjs的新手,我在設置此功能的功能時遇到問題。當複選框被選中時顯示組合框 - Extjs

Ext.onReady(函數(){

var tests = [ 
    ['Test1'], 
    ['Test3'], 
    ['Test2'] 
]; 
Ext.define('Testfile.model.Test', { 
    extend: 'Ext.data.Model', 
    fields: ['test'] 
}); 
var testsStore = new Ext.data.Store({ 
    model: 'Testfile.model.Test', 
    proxy: { 
     type: 'memory', 
     reader: { 
      type: 'array' 
     } 
    }, 
    data: tests 
}); 
var form = Ext.create('Ext.form.Panel', { 
    renderTo: document.body, 
    bodyPadding: 10, 
    width: 550, 
    style: 'margin:16px', 
    height: 300, 
    title: 'Testing example', 
    items: [{ 

      xtype: 'checkbox', 
      name: 'system', 
      boxLabel: 'Production (PACTV)', 
      iputValue: 'production', 

     listeners: { 
      check: function (checkbox, isChecked) { 
        var sample = Ext.getCmp('secondComboID'); 
       } 

     } 
    }, { 
     xtype: 'combobox' 
     fieldLabel: 'Select Test', 
     id: 'secondComboID', 
     store: testsStore, 
     valueField: 'id', 
     displayField: 'test', 
     typeAhead: true, 
     forceSelection: true, 
     allowBlank: false, 
     editable: true, 
     triggerAction: 'all', 
     lastQuery: '' 
    }] 
}); 
Ext.getBody().add(me.form); 

})

可有人請提出一個修正的腳本?

+0

你試圖隱藏和顯示? – dbrin

回答

1

我會用change事件:http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.form.field.Checkbox-event-change

listeners: { 
    change: function(checkbox, newValue, oldValue, eOpts) { 
     var combo = checkbox.up('form').down('combobox'); 
     if (newValue) { 
      combo.show(); 
     } else { 
      combo.hide(); 
     } 
    } 
} 

另外,請注意使用的層級導航方法up()down()。使用這些(或其他相關的方法)來查找組件比使用硬編碼的組件ID更加可取。

這是你的代碼的工作示例:https://fiddle.sencha.com/#fiddle/ua

+0

謝謝!按預期工作。我再次感謝你的幫助:)我還有一個問題,例如:如果在複選框被選中時,我必須在組合框中只顯示幾個字段值,我該如何設置功能? – user2747797

+0

當然,高興地幫助和高興它爲你工作! – existdissolve