2017-04-20 32 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