ExtJS: Премахване и четене на FormPanel в прозорец

Имам проблем, при който искам да премахна FormPanel от прозорец.

Ето моя формуляр, който се зарежда в прозорец:

myForm = new Ext.FormPanel({
    frame: true,
    width: '100%',
    id: 'myform',
    layout: 'form',
    autoHeight: true,
    autoDestroy: false,
    region: 'center',
    monitorValid: true,
    items: [{
        xtype: 'textfield',
        id: 'mytextfield',
        fieldLabel: 'My Label',

    }]
 });

MyWindow =  new Ext.Window({
  title: 'MyWindow',  
    layout: 'auto',
    resizable: false,
  width: 717, 
    autoheight:true,
  id:'mywindow',
    closeAction:'hide',
  closable: true,
    items:[Ext.getCmp("myform")]


  });

Сега искам да премахна този формуляр и трябва да покажа друг формуляр и правя така някъде другаде:

MyWindow.removeAll();
MyWindow.add(Ext.getCmp("myAnotherForm"));

Но това ми дава грешка "Uncaught TypeError: Cannot read property 'events' of undefined" в ext-all-debug.js.

Има ли нещо, което пропускам тук?

Благодаря.


person Arfeen    schedule 15.08.2011    source източник
comment
Заобиколих този проблем, като използвах метода destroy() на формуляра и след това добавих същия формуляр в прозореца.   -  person Arfeen    schedule 16.08.2011


Отговори (1)


Можете да премахнете формуляра и да добавите друг формуляр, като използвате следния код:

Ext.onReady(function() {
    var btn = new Ext.Button({
        id : 'button',
        width : 100,
        height : 30,
        text : 'click me',
        listeners : {
            click : function(){
                var myanother = myAnotherForm;
                var anotherbtn = btn1;
                Mywindow.removeAll();
               Mywindow.add(myanother);
                Mywindow.add(anotherbtn);
                Mywindow.doLayout();
            }
        }
    });
    var btn1 = new Ext.Button({
        id : 'button1',
        width : 100,
        height : 30,
        text : 'Another button'
    });
    myAnotherForm = new Ext.FormPanel({
    frame: true,
    width: '100%',
    id: 'myanotherform',
    layout: 'form',
    autoHeight: true,
    autoDestroy: false,
    region: 'center',
    monitorValid: true,
    items: [{
        xtype: 'textfield',
        id: 'mytextfield',
        fieldLabel: 'My Another Label',
    }]
 });    
    myForm = new Ext.FormPanel({
    frame: true,
    width: '100%',
    id: 'myform',
    layout: 'form',
    autoHeight: true,
    autoDestroy: false,
    region: 'center',
    monitorValid: true,
    items: [{
        xtype: 'textfield',
        id: 'mytextfield',
        fieldLabel: 'My Label',
    }]
 });    
    var Mywindow = new Ext.Window({  
        title: 'MyWindow',       
        layout: 'auto',    
        resizable: false,  
        width: 317,     
        autoheight:true,   
        id:'mywindow',     
        closeAction:'hide',   
        closable: true,
        items : [myForm,btn]    
    });
    Mywindow.show();
});

Работната проба за горното е следната:

http://jsfiddle.net/kesamkiran/MVewR/1/

    * Click on 'click me' button then you will get the another form with another button.If you want to change only form,then you can remove the button.
person Unknown    schedule 16.08.2011