• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 26. JavaScript Project: Creating... > Stage 3: Expanding and Collapsing th...

Stage 3: Expanding and Collapsing the Menu Items

Although you could create a perfectly serviceable menu by displaying all the menu items, in practice you want to give the user some control over which menu items are displayed. This is particularly true if you have a large menu that might require the user to scroll to see all the items.

Giving the user control over the menu means setting up the capability to expand and collapse the nodes. This sounds complex, but it's actually a relatively simple matter given the global nodes_array. All we need to do is set things up so that when we click a node, that node's index property (which, remember, is the node's index within nodes_array) is sent to a function. In turn that function looks up the node in nodes_array and then changes the node's state property to open (if it's current closed) or closed (if it's currently open). The function would then rewrite the tree frame.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint