2014-04-01 94 views
0

我有一個ExtJs窗口,當我點擊一個按鈕時,嘗試在瀏覽器的控制檯中打印某些文本字段的值,它在Firefox中正常工作,但在Chrome中不起作用... I真的很困惑。Extjs getCmp在Chrome中丟失了參考文獻

我試圖讓cmb_start_time和值cmb_end_time,在Firefox的作​​品,但無法在Chrome

Ext.define('form', { 
    extend: 'Ext.window.Window', 

    requires: [ 
     'Ext.form.Panel' 
    ], 

    id:'ticket-form', 
    height: 608, 
    width: 502, 
    closeAction: 'close', 
    title: 'Edit Ticket', 

    initComponent: function() { 
     var me = this; 
     archivopdf = "/pdf/pdf_init.pdf"; 
     Ext.applyIf(me, { 
      items: [ 
       { 
        xtype: 'form', 
        height: 608, 
        width: 498, 
        layout: 'absolute', 
        bodyPadding: 10, 
        title: '', 
        items: [ 

         { 
          xtype: 'combobox', 
          id: 'cmb_start_time', 
          x: 20, 
          y: 180, 
          width: 180, 
          fieldLabel: 'Hora Inicio', 
          store: store_horas, 
          valueField: 'hora24', 
          displayField:'hora12' 
         }, 
         { 
          xtype: 'combobox', 
          id: 'cmb_end_time', 
          x: 20, 
          y: 210, 
          width: 180, 
          fieldLabel: 'Hora Fin', 
          store: store_horas, 
          valueField: 'hora24', 
          displayField:'hora12' 
         }, 
         { 
          xtype: 'button', 
          x: 310, 
          y: 530, 
          text: 'Limpiar', 
          listeners: { 
           click: function(){ 
            console.log(Ext.getCmp('cmb_start_time').getValue()) //returns NULL 
            console.log(Ext.getCmp('cmb_end_time').getValue()) //returns NULL 
          } 
         } 
        ] 
       } 
      ] 
     }); 

     me.callParent(arguments); 
    } 

}); 

var new_window = Ext.create('form') 

我realley需要,使這項工作在Chrome

回答

1

我從創建fiddle您例如,它在Chrome中適用於我(如果沒有選擇任何值,則返回NULL)。

但我不能推薦反正通過引用其ID的組件,所以我改變你的代碼直接引用組件,通過代碼:

在initComponent我們創建組件,節省了參考varthis ,這取決於我們需要它:

initComponent: function() {     
    // ... 

    var firstComboBox = Ext.create('Ext.form.field.ComboBox', { 
     id: 'cmb_start_time', 
     x: 20, 
     y: 180, 
     width: 180, 

我們將引用添加到項目:

this.items = [ 
    { 
     xtype: 'form', 
     height: 608, 
     width: 498, 
     layout: 'absolute', 
     bodyPadding: 10, 
     title: '', 
     items: [ 
      firstComboBox, 

並點擊按鈕,我們可以使用參考:

listeners: { 
    click: function(){ 
     console.log(firstComboBox.getValue()); 
     console.log(secondComboBox.getValue()); 
    } 
} 
+0

謝謝!現在它適用於Chrome和Firefox –