Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Twitter Sign In with OpenID Sign In with Google

Sign In Sign Up

In this Discussion

Tagged

Welcome to the Jo support forums! Please Sign Up and join in the discussion. You can also Sign In instantly with Twitter, OpenID or your Google ID.
It's possible to create a joMenu from an array?
  • ahiniestaahiniesta November 2010
    Posts: 9

    Hello, I'm trying to create a joMenu from an array where I have all the titles and ids. I tried multiles options, but no results. Any idea? Thanks

  • davedave November 2010
    Posts: 415

    Shoot me some sample code, I'll help you sort it out. :) joMenu is definitely geared to work with an array, so I'm guessing maybe it's something small.

    Dave Balmer, Jo Code Wrangler
  • ahiniestaahiniesta November 2010
    Posts: 9

    Something like this, the idea is to have a function that creates the title (createTitle()).

    var listas=new Array();
    for (i=0;i<10;i++){
        listas.push(new Array('title:' + createTitle(i)),'id:'+i));
    }
    

    var menu = new joMenu([listas]);

  • davedave November 2010
    Posts: 415

    That won't work :) You're confusing Array and Object. Here's how I'd write that:

    // better than new Array() for so many reasons
    var list = [];
    
    for (var i = 0; i < 10; i++) {
        // here we're pushing an object onto our array
        list.push({
            title: createTitle(i),
            id: i
        });
    }
    
    var menu = new joMenu(list);
    

    Now, if your menu is static, you could declare it directly inline, as in the example in the documentation for joMenu.

    Also note that the id property is optional. If you do not specify one, the index from the array of menu items is passed instead to any subscribers (again, see the example in the docs for joMenu for a couple use cases).

    Hope this helps!

    Dave Balmer, Jo Code Wrangler
  • ahiniestaahiniesta November 2010
    Posts: 9

    That works perfect. Thanks a lot!!!