tags:

views:

34

answers:

1

Hello! How can i add an item to an existent window? I tried win.add() but it does not seem to work. Why? This is my piece of code:

function combo_service(winTitle,desc,input_param) {

        /* parametri */
        param=input_param.split(","); /* della forma: param[0]="doc1:text", quindi da splittare di nuovo */

   /* cosi' non la creo più volte */
   win;

   if (!win)
    var win = new Ext.Window({
         //title:Ext.get('page-title').dom.innerHTML
        renderTo:Ext.getBody()
        ,iconCls:'icon-bulb'
        ,width:420
        ,height:240
        ,title:winTitle
        ,border:false
        ,layout:'fit'
        ,items:[{
            // form as the only item in window
             xtype:'form'
            ,labelWidth:60
                ,html:desc
            ,frame:true
            ,items:[{
                // textfield
                 fieldLabel:desc
                ,xtype:'textfield'
                ,anchor:'-18'
                }]
        }]
        });

win.add({
            // form as the only item in window
             xtype:'form'
            ,labelWidth:60
                ,html:desc
            ,frame:true
            ,items:[{
                // textfield
                 fieldLabel:desc
                ,xtype:'textfield'
                ,anchor:'-18'
                }]});

    win.show();


}; 

What's wrong with my code? Thank you very much.

+1  A: 
win;

declares win as global, then

var win = ...

redeclares it as a local var when creating the window. Instead, win should be declared non-globally, but outside the scope of wherever this code lives (or passed into it as a function arg). Then just remove the win; line and the var keyword and make sure all code is referencing the same variable.

Also, if the window is already rendered, then you add new components into it, you'll probably have to call win.doLayout() for the window layout to be refreshed.

bmoeskau
thank you very much. This is the final code (for anyone who had my same problems): http://pastebin.com/v7ww7WJc
farhad