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
                }
            }]
            }
        });

我有一个像上面这样的窗口,我想在单击按钮时获取文本输入框的值。

我试过,

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

但错误信息说,

Ext.getCmp('freightFee') 未定义

有人知道吗?

谢谢你!

4

1 回答 1

-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');
}
于 2012-05-16T20:26:55.080 回答