Here is an example (among many others)

//The menu definition
var menu = [
        {title: 'Fruits', entries: [
                {title: 'Apple', entries: [
                        {title: 'Granny Smith'},
                        {title: 'Royal Gala'}
                ]},
                {title: 'Banana'}
        ]},
        {title: 'Vegetables', entries: [
                {title: 'Broccoli'}
        ]}
];

//Recursive function to build the menu
function get_menu(obj) {
        var li = [obj.title];
        if (obj.entries) {
                li.push(Builder.node('ul', obj.entries.collect(function(entry) {
return get_menu(entry); })));
        }
        return Builder.node('li', li);
}

//Build the menu
var ul = Builder.node('ul', menu.collect(function(entry) { return
get_menu(entry); }));

//Add it to DOM
$('menu').appendChild(ul);


On 5/21/07, Jon Trelfa <[EMAIL PROTECTED]> wrote:
> In the past, I've used unordered lists with a recursive function to generate
> it.  You could probably 'roll your own' and end up with about 10-25 lines of
> code depending on the complexity of the tree.
>
>
>  On 5/21/07, szimek <[EMAIL PROTECTED]> wrote:
> >
> >
> > Thank you guys very much for all replies.
> >
> > I don't really need an ajax based menu - I need to fetch an xml or json
> > (I'll probably use json because it tends to create smaller files) file
> using
> > ajax and then use javascript to create a tree menu out of it. The files
> with
> > data can be pretty large, so I need simple xhtml structure that can be
> > created fast with javascript.
> >
> > I'll check other implementations first to see how it works, but probably
> > I'll have to write my own version anyway.
> >
> > Thanks again.
> > --
> > View this message in context:
> http://www.nabble.com/Prototype-based-tree-menu-tf3756726.html#a10718080
> > Sent from the RubyOnRails Spinoffs mailing list archive at Nabble.com.
> >
> >
> > > >
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to