2012-05-16 53 views
0
var confirmWindow = Ext.create('Ext.window.Window', { 
    title: 'Selected Item List', 
    autoHeight: true, 
    width: 500, 
    layout: 'fit', 
    modal: true, 
    items: [{ 
     xtype: 'panel', 
     bodyPadding : 5, 
     items: [{ 
      xtype: 'textfield', 
      id : 'freightFee', 
      fieldLabel: 'Freight Fee ', 
      name : 'freight' // I need this value, when I click the button 
     }] 
    }], 
    bbar: ['->', { 
     xtype: 'buttongroup', 
     items: [{ 
      text: "test", 
      handler: function() { 
       // I want to get the textfield value (freightFee) 
       var freightFee = Ext.getCmp('freightFee').getValue(); // error :Ext.getCmp('freightFee') is undefined 
       } 
      }] 
      } 
     }); 

我有一个类似上面的窗口,我想要获取文本输入框值,当我点击按钮。Extjs4,如何检索单个文本框的值?

我试过,

var freightFee = Ext.getCmp('freightFee').getValue(); 

但错误消息说,

Ext.getCmp( 'freightFee')是未定义

有人知道吗?

谢谢!

+0

仅供参考你的代码是缺少一个右']'结束掉的BBAR阵列,比其他,我使用Ext 4.1.0运行你的代码,并获得我期望的值。 –

回答

-2

千万不要使用getCmp!这是非常昂贵和不必要的。退房up/down方法来定位的元素父母/子女http://docs.sencha.com/ext-js/4-0/#!/api/Ext.Element-method-down

在你的情况类似的东西应该工作:

handler: function(button) { 
    var tf = button.up('window').down('#freightFee'); 
} 
+0

谢谢你的命令,我试着用你的代码,但仍然有错误,错误消息说:button.up('窗口')是未定义的。你能再帮我一次吗? –

+3

Downvote for not use getCmp'ever'。在某些情况下,使用它是完全有效的。此外,它并不昂贵,它只是一个哈希查找,比上/下/孩子便宜得多。 –

+0

无论什么家伙......通过数百/数千个元素进行平面数组查找 - 当然。我的立场 - 不要使用它。这不是必需的。 – sha

相关问题