今天做一个关于动态增减字段的功能,在调用text_field.destroy()的时候..发现输入框确实删了,可它的label竟然仍然留在那里(每次开发到半路总是出现这或那的问题..EXT真是的..#$^%^&%^&#@@XX)..
现在的解决办法一个是使用更加新版的ExtJS,另外一个办法就是重写源码了..重写代码贴在下面(注:不包括重写destroy(), show(), hide(), disable(), enable() )
[2.0.1/2.1] Field.destroy() on Fields rendered by FormLayout does not clean up.
- Ext.override(Ext.layout.FormLayout, {
- renderItem : function(c, position, target){
- if(c && !c.rendered && c.isFormField && c.inputType != 'hidden'){
- var args = [
- c.id, c.fieldLabel,
- c.labelStyle||this.labelStyle||'',
- this.elementStyle||'',
- typeof c.labelSeparator == 'undefined' ? this.labelSeparator : c.labelSeparator,
- (c.itemCls||this.container.itemCls||'') + (c.hideLabel ? ' x-hide-label' : ''),
- c.clearCls || 'x-form-clear-left'
- ];
- if(typeof position == 'number'){
- position = target.dom.childNodes[position] || null;
- }
- if(position){
- c.formItem = this.fieldTpl.insertBefore(position, args, true);
- }else{
- c.formItem = this.fieldTpl.append(target, args, true);
- }
- // Remove the form layout wrapper on Field destroy.
- c.on('destroy', c.formItem.remove, c.formItem, {single: true});
- c.render('x-form-el-'+c.id);
- }else {
- Ext.layout.FormLayout.superclass.renderItem.apply(this, arguments);
- }
- }
- });
参考: http://extjs.com/forum/showthread.php?t=25479