View Full Version : Removing menu items from a menu

14 Jul 2010, 1:38 AM
I'd really appreciate some help on this one. I'm building up a history menu that shows a list of the last 10 items clicked on in a tree. This gets updated and if there are more than 10 items the last item falls off the list. The menu then gets updated with the new items.

The problem is, I can't remove the items, or rather, the removed items are still present in the menu.

where mnu is a reference to the menu object, I've tried looping through items and calling mnu.items.remove(id), mnu.items.remove(obj) and mnu.items.remove(num), all of which results in the mnu.getCount() returning zero.
Also, mnu.removeAll(true) (also tried with false) and mnu.items.clear() seem to remove items and the count is zero.

However, when I add the new items and then access the menu, the items that didn't drop off the list of 10 items are all present twice. The menu then keeps grouping by 10 items every click.

Is there some magic in forcing controls to update or actually remove the items you remove from them as I've had issues elsewhere. Hiding them isn't an option as they will share ids and in certain cases the menu can be reset completely and there won't be a history or rather it will start with no items.

help please...Thanks in advance.

14 Jul 2010, 2:00 AM
I'd just configure my history menu like this:

onAdd: function() {
this.constructor.prototype.onAdd.apply(this, arguments);

// Remove all child items with index >= 10
while (this.items.getCount() > 10) {
this.remove(10, true);

14 Jul 2010, 2:01 AM
Thanks for the reply but tried this already and it doesn't work.

14 Jul 2010, 2:02 AM
I very much doubt that you tried that.

14 Jul 2010, 2:09 AM
It appears I was missing the true in remove. It does of course help if the documentation actually says there's a second parameter which I would have tried and not wasted time with this.

Thanks Animal for your help.

FYI: code I am using was this, minus the ,true of course:

for (var itm=this.backMnu.items.getCount()-1;itm>=0;itm--) {
this.backMnu.remove(itm, true);

14 Jul 2010, 2:19 AM
Indeed I hate timewasting.


14 Jul 2010, 2:22 AM
my bad. was looking at the remove in MixedCollection.