PDA

View Full Version : removing buttons from a toolbar



maya
20 Apr 2007, 2:25 PM
Hi,

I created a toolbar and added 5 buttons.
Then, I wanted to implement a function that clears some or all of the 5 buttons and adds new ones (to the same toolbar).

How can I do it?

Thanks,
Maya

tryanDLS
20 Apr 2007, 4:01 PM
You should be able to hide and/or destroy a toobar item. There's no facility for retrieving an item from the toolbar, so you'll have to maintain refs to the buttons in order to remove them.

maya
21 Apr 2007, 4:24 AM
I keep the toolbar object as a global var. Can I destroy it/clear it from its buttons? I tried to do it - but I acn't find any relevant function for that.

Thanks,
Maya

amon
21 Apr 2007, 4:45 AM
something like this?

toolbar.items.each(function(item){item.destroy();});

It is just an idea. I can not try it now. :(

maya
21 Apr 2007, 5:14 AM
Thanks for trying to help.

I tried your suggestion, but I receive an error from using the destroy function.
Any suggestion?

Also, I can access the javascript variable for each button - can I override its content?

Thanks again,
Maya

soad
21 Apr 2007, 6:51 AM
Hi,

I'm using Final 1.0. I tried this code and it works for me:



while (tb.items.getCount() > 0)
{
var item = tb.items.itemAt(0);
tb.items.removeAt(0);
item.destroy();
}


Where tb holds a reference to an instance of Ext.Toolbar.

HTH

P.S.

Generally, traversing a collection and removing items from it at the same time is not a good idea.

maya
21 Apr 2007, 11:38 PM
Thanks soad, it works just fine.

I wanted to ask you 2 more questions regarding this issue:
1. What is the risk in this loop? You remove them according to the loop's sequence.
2. How did you figure out that the code line: "parent.tb1.items.removeAt(0);" is needed? I am reading the documentation again and again and can't figure out the required code sequence. (I tried the item.destroy() - and it didn't work).

A more general question is: what is the best way to learn how to use the ext functionality?

Thanks,
Maya

Animal
22 Apr 2007, 7:42 AM
The answer to question 2 and the general question is: "read source code".

soad
22 Apr 2007, 7:17 PM
I dug through source code and found out that destroy() only removes DOM elements, and doesn't remove the button from toolbar's items collection. That's why you have to explicitly call tb.items.removeAt(0).

The way I learn Ext is this: first of all, I look into documentation. Since I use it often I installed a local copy of it. If I don't find the quick answer there I go to this forum and first search for answers. If I don't find the answer, I create a new thread with my question. If neither of the above works (though, it almost always works) I look through source code.

maya
22 Apr 2007, 10:37 PM
Thanks.

And how do you find the possible list of value for functions' input strings?
For example, the possible event strings sor the "addListener" function?

Thanks,
Maya

Animal
22 Apr 2007, 11:38 PM
The documentation! It lists events for each class with a link right at the top.