tags:

views:

432

answers:

2

Hey everyone,

I know this might be a weird question by I'm having trouble trying to find my own item by id. Allow me to explain what I'm trying to do...

Here's what possible...

var myMenu = new Ext.menu.Menu({
    id: "my-menu",
    items: [{
        id: "first-item",
        text: "hello"
    }]
});

When I do this...

myMenu.findById('first-item');  // it will return a component...

HOWEVER, when I try to extend it in such a way...

NewMenu = Ext.extend(Ext.menu.Menu, {

    id: "",
    win_id: "",

    initComponent: function(){
         // All the neccessary code
    },

    onRender: function(){
         // codes...
    },

    // Override the add function
    add: function(){
         this.findById(this.win_id); // return NULL
    }
});

Sorry for my missing codes. I understand that it could be along the line that the object has not render after it added the item, hence it will return NULL. Is there any way I can do it? I'm using ExtJS 3.0 hence, there is no "onAdd" method to override. Not sure it will help.

Let me know if I miss any impt information.

Cheers and thanks a mil, Mickey

A: 

The second parameter of Ext.extend() should be an object, not a function:

NewMenu = Ext.extend(Ext.menu.Menu, {

    id: "",
    win_id: "",

    initComponent: function(){
         // All the neccessary code
    },

    ...

EDIT: if syntax is not the issue then I guess you are right about that the object has not render after it added the item. I think this is an important-to-know limitation that a component is not completely initialized until the underlying DOM element is inserted and rendered in the document.

Maybe I can suggest something if you would explain what you want to do with the return value of this.findById(this.win_id), like delaying the menu items initialization until at least the win_id element has been rendered.

Lukman
oops, my bad... the code works perfectly fine, as in error-free in Firebug except that when I do the add action, it returns null during the execution of this.findById(). Any hint?
Mickey Cheong
in fact, i'm using the return of "this.findById(this.win_id)" inside a .on('show', function(){ /* ... here ... */}). It will be use later when the event show triggered by the window. In short, I will be attached a listener after I add an item such that when the window trigger, it will refer back to the added item and manipulate it.
Mickey Cheong
+1  A: 

do you have this in NewMenu.initComponent ?

NewMenu.superclass.initComponent.call(this);
jujule
Yup... I used another method to handle it. Thanks.
Mickey Cheong