preventing duplicates in umenu
I have a umenu that is populated by javascript. However, sometimes the output of the javascript is already in the umenu. In this case I need to prevent the duplicate from being added. How may I do this?
Thanks much in advance
Joe
I usually just send a 'clear' message to the umenu first
I mean, for append messages. I don't rebuild the menu, I just add stuff to it.
You didn't mention a coll!
I don't know offhand whether the umenu has an attribute to prevent duplicates but in general it's not a good idea to use a view as the model as well.
Keep your collection of data stored somewhere else (in a model) and handle (prevent) duplicates there.
Then whenever there's a change, your model will update umenu. The easy way to do that if you don't want your model to keep track of what it has previously sent, is to clear the umenu and resend everything.
there is a patch that does this in the st.ools collection called St.oleMenu
But I would second the advice about keeping the list elsewhere--esp as you can't get umenu to dump its contents afaik. I'm pretty sure St.oleMenu does this itself.
If you're doing this in javascript you should be able to check the [umenu] objects "items" attribute and use an if statement to make sure that the string you want to add isn't already present.
Let me know if you'd like an example patch for this.
here's a way to not append if it's already in there, but i used objects, not js, so i don't know if this can help you.
O.