2017-04-20 48 views
0

我有一段代碼,當複選框被選中時,組合框會激活。一旦複選框被選中,我可以從組合框中選擇一個值。但是,一旦複選框未選中,我希望組合框返回沒有值(空白)。我怎麼做? 我的代碼如下:使組合框的值爲空

var tests = [ 
['Test1'], 
['Test3'], 
['Test2'] 
]; 
Ext.define('Test', { 
    extend: 'Ext.data.Model', 
    fields: ['test'] 
}); 
var testsStore = new Ext.data.Store({ 
    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: 'checkboxfield', 
     name: 'system', 
     boxLabel: 'Production (PACTV)', 
     inputValue: 'production', 
     listeners: { 
      change: function (checkbox, newValue, oldValue, eOpts) { 
       var combo = checkbox.up('form').down('combobox'); 
       if (newValue) { 
        Ext.getCmp('secondComboID').setReadOnly(false); 
        Ext.getCmp('secondComboID').allowBlank = false; 
        Ext.getCmp('secondComboID').validate(); 
       } else { 
        Ext.getCmp('secondComboID').setReadOnly(true); 
        Ext.getCmp('secondComboID').allowBlank = true; 
        Ext.getCmp('secondComboID').validate(); 
       } 
      } 
     } 
    }, { 
     xtype: 'combobox', 
     fieldLabel: 'Select Test', 
     readOnly: true, 
     id: 'secondComboID', 
     store: testsStore, 
     valueField: 'id', 
     displayField: 'test', 
     typeAhead: true, 
     forceSelection: true, 
     editable: true, 
     triggerAction: 'all', 
     lastQuery: '' 
    }] 
}); 

這裏是工作提琴:https://fiddle.sencha.com/#view/editor&fiddle/1u9n

回答

1

使用這個在你的提琴,當您取消選中該複選框:

Ext.getCmp('secondComboID').reset(); 
+1

您節省了很多我的時間伴侶。謝謝 –

0

使用此代碼刪除DATAS從組合或加載組合中的空陣列數據

Ext.getCmp('secondComboID').getStore().loadRawData([]); 

此外,如果您希望再次加載以前的數據,這裏是一個例子,它允許我們切換到加載數據並從組合中刪除數據。FIDDLE