2011-09-13 35 views
1

我有一个组合框,具有以下配置。ExtJs4 - 自动完成ComboBox不显示空文本

{ 
    fieldLabel:'Service', 
    xtype:'combo', 
    displayField: 'srvcDesc', 
    store: storeServiceCodeVar, 
    valueField:'srvcCD', 
    id:'serviceCodeId', 
    name:'serviceCodeName', 
    queryMode: 'remote', 
    queryDelay:100, 
    typeAhead: true, 
    minChars:0, 
    hideTrigger:true, 
    forceSelection:true, 
    maxHeight:23, 
    deferEmptyText:false, 
    autoSelect:true, 
    fieldStyle:'text-transform:uppercase', 
    listConfig: { 
     loadingText: 'Loading...', 
     // Custom rendering template for each item 
     getInnerTpl: function() { 
      return '<table width="200px"><tr><td height="5"></td></tr><tr valign="top"><td>Code:{srvcCD}</td></tr><tr><td height="2"></td></tr><tr valign="top"><td>Description:{srvcDesc}</td></tr><tr><td height="5"></td></tr></table>'; 
     }, 
     emptyText:'No Values Found' 
    } 
} 

的问题是,当没有从服务器返回的数据,然后emptyText(其值 - 没有找到值)被显示可能是一个毫秒和熄灭。我希望它留在那里直到下一个查询被解雇。这怎么可能。我用deferEmptyText尝试过,但没有运气。

有人可以对此有所了解。我使用的是ExtJS 4,在IE9和Mozilla中行为相同。

在此先感谢。

+0

也在苦苦挣扎着;它看起来像预期的那样将emptyText值添加到了DOM,但是当从服务器没有返回记录时,包含元素的高度被设置为0。目前通过Ext JS 4源代码寻找灵感...... –

回答

2

从单步穿过源代码看来,似乎没有任何关于listConfig.emptyText用于确定是否将元素的高度设置为零以外的数字的引用。

我已经结束了覆盖Ext.form.field.ComboBox从Ext.form.field.Picker继承的alignPicker()函数,并添加了一个listConfig.emptyText的检查。

Ext.override(Ext.form.field.ComboBox, { 

    alignPicker: function() { 
     var picker, height; 

     if (this.isExpanded) { 
      // Get the picker component. 
      picker = this.getPicker(); 

      if (this.matchFieldWidth) { 
       // Set the default height to null, since we don't 
       // automatically want to have the height changed. 
       height = null; 

       // If our store exists, but the count is zero 
       // and we've got no emptyText defined... 
       if (picker.store && 
        picker.store.getCount() === 0 && 
        Ext.isEmpty(this.listConfig.emptyText)) { 
        // ...we set the height to zero. 
        height = 0; 
       } 

       // Set the size of the picker component. 
       picker.setSize(this.bodyEl.getWidth(), height); 
      } 

      if (picker.isFloating()) { 
       this.doAlign(); 
      } 
     } 
    } 

}); 

希望这有助于!

+0

嘿丹尼尔,感谢分享黑客。这很棒。对我来说,当单独创建组合框时,emptyText工作得很好,但当与剩余应用程序的代码合并时,它将停止显示。我也试图找出哪个部分影响了emptyText的行为。如果发现有用,我会在这里分享。感谢你的宝贵时间。 – netemp

+0

嗨 - 我不确定我了解你的问题。 “独立创造”是什么意思?你现有的应用程序是什么?上面描述的组合框的emptyText问题是Ext JS 4中的一个已知错误(请参阅http://www.sencha.com/forum/showthread.php?147005-4.0.6-Combobox-listview-collapsed-when-an -empty-array-is-returned),并且暂时这个黑客应该解决你的问题。 –

+0

感谢丹尼尔的职位。通过提及'独立创建'我的意思是,如果我创建一个测试页面并包含extjs库并测试emptyText,那么它对我来说工作正常。但是当我将它包含在我的应用程序中时,它不起作用。我在进一步调查事物时发现了这一点,并意识到这可能是由于我们在应用程序中修改了某些内容。但看看你提供了什么,这整个情况看起来像是混乱。感谢分享黑客。 – netemp

0

这里有个警告。我在ExtJs 4-0-6上,似乎现在有一些代码在Ext.form.field.ComboBox,它不再仅仅依靠继承Ext.field.form.Picker的方法。

因此,相反上述代码现在应该直接在Ext.field.form.Picker而不是在ComboBox中覆盖代码。

但无可否认,希望Sencha能很快在4.1中解决这个问题。