2013-08-01 7 views
6

में पहला आइटम का चयन करने के मैं एक कॉम्बो देखने http://jsfiddle.net/Q5nNV/ExtJS 4.1 कैसे कॉम्बो

enter image description here

सब कुछ अच्छी तरह से है जैसे है, लेकिन जब मैं खोज (टाइपिंग) कॉम्बो बॉक्स को asdf की तरह कुछ पाठ और स्पष्ट क्लिक करें बटन

यह पहला आइटम का चयन नहीं कर रहा है, यह

enter image description here

की तरह लग रहे

यहाँ मेरी कोड

var states = Ext.create('Ext.data.Store', { 
    fields: ['abbr', 'name'], 
    data : [ 
     {"abbr":"AK", "name":""}, 
     {"abbr":"AL", "name":"Alabama"}, 
     {"abbr":"AZ", "name":"Arizona"} 
    ] 
}); 

// Create the combo box, attached to the states data store 
var combo = Ext.create('Ext.form.ComboBox', { 
    fieldLabel: 'Choose State', 
    store: states, 
    triggerAction: 'all', 
    value: "AK", 
    queryMode: 'local', 
    displayField: 'name', 
    valueField: 'abbr', 
    trigger2Cls: 'x-form-clear-trigger', 
    onTrigger2Click: function (args) { 
     this.setValue("AK"); 
    }, 
    tpl: new Ext.XTemplate('<tpl for=".">' + '<li style="height:22px;" class="x-boundlist-item" role="option">' + '{name}' + '</li></tpl>'), 
    renderTo: Ext.getBody() 
}); 

मैं चाहता हूँ जब मैं स्पष्ट बटन पर क्लिक करें मेरी कॉम्बो पहले आइटम (खाली आइटम) का चयन करेंगे। इसे कैसे ठीक करें

उत्तर

6

यह चाल चलाना चाहिए। आप मूल रूप से पहले मान का चयन करने की जरूरत है, ताकि यह फिल्टर साफ कर सकते हैं और उसके बाद क्षेत्र के लिए वापस ध्यान केंद्रित (वैकल्पिक) भेजने इसे फिर से क्वेरी बनाने:

Ext.onReady(function() { 
    // The data store containing the list of states 
    var states = Ext.create('Ext.data.Store', { 
     fields: ['abbr', 'name'], 
     data : [ 
      {"abbr":"AK", "name":""}, 
      {"abbr":"AL", "name":"Alabama"}, 
      {"abbr":"AZ", "name":"Arizona"} 
     ] 
    }); 

    // Create the combo box, attached to the states data store 
    var combo = Ext.create('Ext.form.ComboBox', { 
     fieldLabel: 'Choose State', 
     store: states, 
     triggerAction: 'all', 
     queryMode: 'local', 
     displayField: 'name', 
     valueField: 'abbr', 
     trigger2Cls: 'x-form-clear-trigger', 
     enableKeyEvents: true, 
     onTrigger2Click: function (args) { 
      // Select the first record in the store 
      this.select(this.getStore().getAt(0)); 
      // Force a re-query to clear the filter 
      this.doQuery(); 
      // Send focus back to the field 
      this.focus(); 
     }, 
     tpl: new Ext.XTemplate('<tpl for=".">' + '<li style="height:22px;" class="x-boundlist-item" role="option">' + '{name}' + '</li></tpl>'), 
     renderTo: Ext.getBody() 
    }); 
}); 
जाहिर

, फिर से क्वेरी और ध्यान वैकल्पिक हैं । आप उन्हें आसानी से इस कोड से हटा सकते हैं।

वैकल्पिक रूप से, आप this.select(this.getStore().getAt(0)); का उपयोग कर सकते हैं और फिर इसे चुनने के लिए this.blur() कर सकते हैं और फिर तुरंत अप्रचलित सूची से छुटकारा पा सकते हैं।

+0

हाँ धन्यवाद, यह अच्छा है – freestyle

14

यह मेरे

var combo = Ext.getCmp('myId'); 
combo.select(combo.getStore().getAt(0)); 
0

लिए काम करता है यह मेरे लिए काम है ....

 var cmbESTADO = component.query('#cmbESTADO')[0]; 
     cmbESTADO.store.load(function(st){ 
      cmbESTADO.select(cmbESTADO.getStore().getAt(0)); 
     }); 

जब बता गया लोड नहीं किया जाता है, का चयन काम नहीं। लोड से पहले और फिर चुनें।

+0

कृपया, अपना कोड टिप्पणी करें। – Beppe

संबंधित मुद्दे