2016-09-16 107 views
0

我在我的应用程序中设置了一个ComboBox。组合有emptyText和我设定的默认值。ExtJS Combo默认值返回null

我希望保留'7AM'文本和'7'作为默认值。但是当我尝试通过选择'7AM'来提交页面时,则返回值null

// The data store containing the list of states 
var states = Ext.create('Ext.data.Store', { 
    fields : [ 
     'id', 
     'text' 
    ], 
    data: [ 
     { 
      'id':'3', 
      'text':'3AM' 
     }, 
     { 
      'id':'4', 
      'text':'4AM' 
     }, 
     { 
      'id':'5', 
      'text':'5AM' 
     }, 
     { 
      'id':'6', 
      'text':'6AM' 
     }, 
     { 
      'id':'7', 
      'text':'7AM' 
     } 
    ] 
}); 

// Create the combo box, attached to the states data store 
Ext.create('Ext.form.ComboBox', { 
    fieldLabel: 'Choose State', 
    store: states, 
    queryMode: 'local', 
    displayField: 'text', 
    valueField: 'id', 
    emptyText: '7AM', 
    value: '7', 
    renderTo: Ext.getBody(), 
    listeners: { 
     'select': function(cbo){ 
      alert(cbo.getValue()); 
     } 
    } 
}); 

上面是测试代码,你可以建议为什么当我选择7AMnull被惊动?

+1

您是否发布了如何提交组合详细信息的代码? – Saloo

+0

您可以查看上面的代码。当您选择7AM时,它会提醒您null null –

+0

我已经在ExtJS 4中运行了此代码,并且我没有收到空值。首先7AM已经被选中,所以即使你选择7AM,它也不会触发事件。当我选择其他号码时,我获得了适当的价值。然后我再次选择7AM,我得到7作为警报值。 – Saloo

回答

0
// The data store containing the list of states 
var states = Ext.create('Ext.data.Store', { 
    fields : ['id', 'text'], 
    data: [{'id':'3','text':'3AM'}, {'id':'4','text':'4AM'}, {'id':'5','text':'5AM'},{'id':'6','text':'6AM'},{'id':'7','text':'7AM'}] 
}); 

// Create the combo box, attached to the states data store 
Ext.create('Ext.form.ComboBox', { 
    fieldLabel: 'Choose State', 
    store: states, 
    itemId: 'combo', 
    queryMode: 'local', 
    displayField: 'text', 
    valueField: 'id', 
    //emptyText: '7AM', 
    //value: '7', 
    renderTo: Ext.getBody(), 
    listeners: { 
     'select': function(cbo){ 
      alert(cbo.getValue()); 
     }, 
     'afterrender': function(cbo) { 
      cbo.setValue("7"); 
     } 
    } 
}); 
0

你的例子似乎没有问题。 所以你的问题必须在别的地方,而不是在组合本身。

1-检查应用程序中控制台是否没有错误。

2-检查商店是否在您检查它的价值时被加载。

3-检查渲染后是否没有事件更改组合值。