How to get to a yuimenu object after it's been created?
I'm got some yuimenu-based popup menus working, and, generally speaking, all is well. However, I've found that I need to get my hands on a menu object so I can do things to it after it's been created (e.g., hide an exposed menu when something else happens on the page). I can find the div of class yuimenu, but I need the object so I can (presumably) do a cfg.setProperty('visibility', 'hidden')
or something similar on it.
So: How can I get this object? I've tried Y开发者_Go百科AHOO.widget.Menu(theDivID)
, but that went down in flames. Thanks! (ps: If I'm going about this all wrong, please let me know!)
I've figured out a way to do this, but I can't say I'm very pleased with it:
Declare
allTheMenus,
a global javascript variable meant to collect all the yuimenu items that will be placed on the page.When the page is built, push each menu instance onto this variable/array.
When the Special Event occurs (in my case, the user clicking on a link that brings up an overlay dialog div to collect some user input), do the following:
- Check the page to see if there are any items of class yuimenu whose style is visible (e.g,.
$('.yuimenu[style*=visible]')...
- If there is one (in my case, there can be only one; your situation may vary), get its ID and (ugh) loop through the global array of all yuimenu instances and find the one that has the same ID.
- Do
this.cfg.setProperty('visible', false)
on it and bail out of the loop (again, assuming there is only one item that might be visible).
- Check the page to see if there are any items of class yuimenu whose style is visible (e.g,.
Like I said -- I'm not proud of the code, but it's working. I would LOVE for someone to show me that there's a better way to do it...
精彩评论