2014-02-18 47 views
0

雖然我檢查了關於同一問題的其他帖子,但它們並沒有證明是非常有用的。 下面是代碼,我試圖獲得文本框的價值,但我一再得到相同的錯誤。 有沒有其他可用的方法。Ext.getCmp undefined

initComponent: function() { 
    this.items = [ 
     { 
      xtype: 'form', 
      padding: '5 5 0 5', 
      border: false, 
      style: 'background-color: #fff;', 

      fieldDefaults: { 
       anchor: '100%', 
       labelAlign: 'left', 
       allowBlank: false, 
       combineErrors: true, 
       msgTarget: 'side' 
      }, 

      items: [ 
       { 
        xtype: 'textfield', 
        name : 'id', 
        fieldLabel: 'id', 
        hidden:true 
       },  
       { 
        xtype: 'textfield', 
        name : 'name', 
        id : 'idname', 
        fieldLabel: 'Name', 
        allowBlank:false, 
        blankText:'Name is required' 
       }, 
       { 
        xtype: 'textfield', 
        name : 'accno', 
        maxLength: 16, 
        enforceMaxLength : true, 
        regex: /^.{16}$/, 
        regexText:'Only 16 Digits please', 
        //autoCreate: {tag: 'input', type: 'text', size: '20', autocomplete: 'off', maxlength: '10'}, 
        fieldLabel: 'AccNo' 
       }, 
       { 
        xtype: 'textfield', 
        name : 'trade', 
        fieldLabel: 'Trade' 
       }, 
       { 
        xtype: 'datefield', 
        name : 'doi', 
        fieldLabel: 'Date Of Insurance', 
        editable: false, 
        value : new Date() 
       }, 
       { 
        xtype: 'datefield', 
        name : 'dd', 
        fieldLabel: 'Due Date', 
        editable:false, 
        value : new Date() 
       } 
      ] 
     } 
    ]; 

    this.dockedItems = [{ 
     xtype: 'toolbar', 
     dock: 'bottom', 
     id:'buttons', 
     ui: 'footer', 
     items: ['->', { 
      iconCls: 'icon-save', 
      itemId: 'save', 
      text: 'Save', 
      handler: function (button) { 
       Ext.Msg.alert('You clicked the button'); 
       var txt = Ext.getCmp('idname').value(); 
       //var tf = button.up('window').down('#idname'); 

       Ext.Msg.alert(txt); 

      }, 
      action: 'save' 
     },{ 
      iconCls: 'icon-reset', 
      text: 'Cancel', 
      scope: this, 
      handler: this.close 
     }] 
    }]; 

    this.callParent(arguments); 
} 

});

+0

你可以嘗試(''的的getValue),而不是'值()',這是否正確的問題? – weeksdev

+0

@weeksdev試過但仍然得到相同的錯誤「TypeError:Ext.getCmp(...)未定義」 –

回答

0

我會嘗試Ext.ComponentQuery.query method

在您的按鈕,檢查

xtype: 'toolbar', 
    dock: 'bottom', 
    id:'buttons', 
    ui: 'footer', 
    items: ['->', { 
     iconCls: 'icon-save', 
     itemId: 'save', 
     text: 'Save', 
     scope:this, 
     handler: function (button) { 
      Ext.Msg.alert('You clicked the button'); 
      var txtfield = this.query('#idname'); 
      var txt = txfield.getValue(); 
      Ext.Msg.alert(txt); 

     }, 
     action: 'save' 
    } 
+0

試過你的解決方案,但我得到這個錯誤** TypeError:this.query不是函數** (My Ext版本是4.0.0) –

+0

我想我應該問,你在這個課程中延續了什麼課程? –

+0

Ext.window.Window –