extjs 获取id的值,如何从Ext窗口文本框中获取用户输入值?

I have a webpage with buttons designed in Extjs. When the user clicks 1 of these buttons, a window appears with a textfield and a next button. Clicking the next button will load another window with fieldsets, hiding the first one. The number of fieldsets in the second form is to be adjusted according to the user input in the first window. I am trying to use a for loop for this.

The code I am using as follows:

var win1, win 2, j;

var win1items = new Ext.form.FormPanel({

//snip

items: [{

xtype: 'fieldset',

defaultType: 'textfield',

items: [{

fieldLabel: 'Number',

allowBlank: false,

name: 'Number',

width: 110,

cls:"txtfield"

}]

}],

buttons: [{

text: 'Next',

handler: function(){

if(!win2){

winc2 = new Ext.Window({

//snip

items: [win2items]

});

}

win2.show(this);

win1.hide();

}

}]

});

j = Ext.getCmp('win1').getForm().findField("Number").getValue();

var fldComs = [];

for (i=0; i<=j; i++){

fldComs[i] = new Ext.form.FieldSet({

//snip

items: [{

//snip

}]

});

}

win2items = new Ext.form.FormPanel({

//snip

items: [fldComs]

});

Ext.onReady(function(){

new Ext.Toolbar({

renderTo: document.body,

items: [{

xtype: 'tbbutton',

text: 'Start Here',

cls: 'menu-icon',

handler: function(){

if(!win1){

win1 = new Ext.Window({

//snip

items: [win1items]

});

}

win1.show(this);

}

}]

});

});

The error I am getting is

Uncaught TypeError: Cannot call method 'getForm' of undefined.

However if i am using a fixed value in the for loop, say 5 I am getting the desired output. I am using Ext 3.2.1

解决方案

Your code is full of reasons for it to not work - I'm not trying to be mean, but from a troubleshooting standpoint it's hard to tell where the real problem is with so much guess work - the things I'm seeing:

1) Your call to Ext.getCmp('win1') fails because there is nothing with the id of 'win1' - try:

var win1items = new Ext.form.FormPanel({

id: 'win1'

...

2) If you meant for the id of 'win1' to be on the window you create in the handler, you need to specify that there but, as pointed out by MMT, Ext.Window does not have the getForm() method (so I doubt this is what you're trying to do).

3) If you want the value of that text field, just do it the easy way and give the field an ID:

[{

label: 'Number',

xtype: 'textfield',

id: 'MyNumberField'

}]

...

var j = Ext.getCmp('MyNumberField').getValue();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值