ee3a84w
Thursday, January 8, 2009

when components get there elements?

  • i have code like this
    var p=new Ext.panel({id:'panel1'});
    var el=p.getEl();
    el.on('click',function(){},this);

    ext complain that el have no properties ,so i guessed that no el have been constructed yet for the panel component, so:
    when the element is available,
    OR how can i force Ext to make one immediatly to work on
    thanx


  • If you want your panel to be rendered immediately, then you have to include a renderTo config property, for example:


    var p=new Ext.panel({id:'panel1', renderTo: document.body});
    p.getEl().on('click', function(){}, this);


    You can also use deferred rendering, calling the panel's render() method at a later point:


    var p=new Ext.panel({id:'panel1'}); // at this point the panel does not have an associated element
    p.render(document.body); // the panel gets its element here
    p.getEl().on('click', function(){}, this);


    In any case, if you are interested in attaching an event handler to the click event for the panel's element, you may also use this technique:


    var p=new Ext.panel({
    id:'panel1',
    listeners: {
    'render': function(panel) {
    panel.getEl().on('click', function(){}, scope);
    }
    }
    });


  • fawzyj you need to add extra code to get the panel rendered into the page DOM.

    First your panel probably needs to be added to a parent Viewport container otherwise how will Ext know where to render it into the browser page? Then a call to a render() or doLayout() function will sort your code out. I am still alittle fuzzy on whether both render and doLayout are required.


  • Not sure if I'm following.

    What happens if you change your second line to:


    var el = getEl("panel1");
    ...and I'm not sure what you're trying to do in the third line of code. I'd make a reference to a function rather than call it there...like so:


    el.on('click',elClick);
    ...where elClick is a function (event handler) you've defined in your private functions space to handle the click event.

    Does that help?







  • #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about when components get there elements? , Please add it free.