2013-02-20 94 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

相关问题