【问题标题】:Extjs Combo diplay value - if value is not foundExtjs Combo 显示值 - 如果未找到值
【发布时间】:2012-12-15 10:18:08
【问题描述】:

我正在使用这种技术来完成组合框 http://cdn.sencha.com/ext-4.1.1a-gpl/examples/form/forum-search.html 的自动完成功能,它返回汽车的名称和类型,有时类型未知所以没有返回,我希望它是“无数据" 所以我用了这个valueNotFoundText: 'No Data' 但没用

xtype: 'combo',
store: s,
hideTrigger:true,
typeAhead: false,
id: 'search',
queryMode: 'remote',
queryParam: 'query',
displayField: 'name',//+'type',
valueField: 'name',//+'type',
//valueNotFoundText: 'No Data',
 ,listConfig: {
                loadingText: ' Loading...',
                getInnerTpl: function() {
         return  '{name}'+'<br>'+'<p><font size="1">{type}'+':type</font></p>';
                }
                ,
            }
            ,  listeners: { 

【问题讨论】:

    标签: javascript extjs autocomplete


    【解决方案1】:

    我猜你正在寻找这种(简化的工作示例)。

    Ext.create('Ext.form.ComboBox', {
        fieldLabel: 'Choose State',
        store: states,
        typeAhead: true, // this will simply show the typed text if nothing is found.
        queryMode: 'local',
        displayField: 'name',
        valueField: 'abbr',
        tpl: Ext.create('Ext.XTemplate',
            '<tpl for=".">',
                   '<div class="x-boundlist-item">{abbr}</div>',
            '</tpl>'
        ),
        displayTpl: Ext.create('Ext.XTemplate',
            '<tpl for=".">',
                '<tpl if="name.length == 0"> ',             
                   'no data', // You can return any other additional value or formating here
                '<tpl else>',
                   '{name}', // You can return any other additional value or formating here
                '</tpl>',                                  
            '</tpl>'
        ),
        valueNotFoundText: 'no data' // this will be displayed if no record is found after setValue()
    });
    

    这是一个有效的JSFiddle

    那么这是如何工作的

    只需为下拉菜单设置模板(如果您的情况完全需要)并为显示字段设置模板。

    这两个例子都是简化的,因为我不知道你的整个模板。

    更新示例

    注意:我不会使用 type 作为属性名称,因为这是一个保留名称,因为它标识了字段对象/基元的类型

    var states = Ext.create('Ext.data.Store', {
        fields: ['abbr', 'name','ctype'],
        data : [
            {"abbr":"AL", "name":"Alabama", "ctype":"AL"},
            {"abbr":"AK", "name":"Alaska", "ctype":"AK"},
            {"abbr":"AZ", "name":"Arizona", "ctype":""}
        ]
    });
    
    // Create the combo box, attached to the states data store
    Ext.create('Ext.form.ComboBox', {
        fieldLabel: 'Choose State',
        store: states,
        typeAhead: true, // this will simply show the typed text if nothing is found.
        queryMode: 'local',
        displayField: 'name',
        valueField: 'abbr',
        tpl: Ext.create('Ext.XTemplate',
            '<tpl for=".">',
                '<tpl if="ctype.length == 0"> ',             
                   '<div class="x-boundlist-item">{name}<p><font size="1">no data</font></p></div>',
                '<tpl else>',
                   '<div class="x-boundlist-item">{name}{ctype}<p><font size="1">{ctype}</font></p></div>',
                '</tpl>',
            '</tpl>'
        ),
        displayTpl: Ext.create('Ext.XTemplate',
            '<tpl for=".">',
                '<tpl if="itype.length == 0"> ',             
                   'no data',
                '<tpl else>',
                   '{name}', 
                '</tpl>',                                  
            '</tpl>'
        ),
        valueNotFoundText: 'no data', // this will be displayed if no record is found after setValue()
        renderTo: Ext.getBody()
    });
    

    JSFiddle

    【讨论】:

      【解决方案2】:

      您可以在列表配置http://docs.sencha.com/ext-js/4-1/#!/api/Ext.view.AbstractView-cfg-emptyText 中使用emptyText 配置选项。 ComboBoxes 内部列表类 BoundList 从 View 扩展,因此它遵循相同的 api。 http://docs.sencha.com/ext-js/4-1/#!/api/Ext.form.field.ComboBox-cfg-listConfig

      listConfig: {
          emptyText: 'No Data'
      }
      

      【讨论】:

      • 谢谢,但是当没有任何结果时,这将显示消息。但在我的情况下,名称总是返回但类型不......所以结果将是:name:mike type: 。 . 所以,当类型为空时,我需要它是“无数据”。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-31
      相关资源
      最近更新 更多