2013-02-20 39 views
2

截至How to add an empty item to ExtJS combobox?說我可以看到根據需要一個空白行/項目我實現了,但之後我無法從組合框中選擇任何項目!無法從組合框中選擇添加空項/行

任何猜測?

我的代碼遵循

var rModel = Ext.regModel('State', { 
    fields: [ 
    {type: 'string', name: 'fips_state_code'}, 
    {type: 'string', name: 'state_name'} 
    ] 
}); 

// The data store holding the states 

var store = Ext.create('Ext.data.Store', { 
    model: 'State', 
    data: [{fips_state_code: '0', state_name: ' '}] 
}); 

store.add(obj.results); 

{ 
     xtype:'combo', 
     id:'filterstate', 
     width: 250, 
     fieldLabel: 'Filter By State', 
     store: store, 
     queryMode: 'local', 
     displayField: 'state_name', 
     valueField: 'fips_state_code', 
     editable: false, 
     forceSelection : true, 
     triggerAction : 'all', 
     typeAhead: true, 
     selectOnFocus:true, 
     allowBlank:true, 
     tpl : '<tpl for=\".\"><div class=\"x-combo-list-item\">{state_name}&nbsp;<\/div><\/tpl>' 

    } 

回答

2

的問題是第三方物流的屬性,以便選擇你需要的X-boundlist項目類添加到您的TPL的屬性。就這樣

tpl : '<tpl for=".">'+ 
      '<div class="x-boundlist-item">'+ 
       '<div class="list-item">{state_name}&nbsp;</div>'+ 
      '</div>'+ 
     '</tpl>' 

http://jsfiddle.net/alexrom7/CnwpD/

但是如果你只想要一個自定義CSS類適用於每一個項目的組合框列表。我建議你做這樣

listConfig: { 
// Custom rendering template for each item 
      getInnerTpl: function() { 
       return '<div class="list-item">{state_name}&nbsp;<\/div>'; 
      } 
     } 

http://jsfiddle.net/alexrom7/6Jt5T/

直接與TPL工作可以給你一些麻煩。

+0

謝謝alexrom7。有用。乾淨的解決方案。 – Ankit 2013-02-21 16:36:48

相關問題