Loading ...
Sorry, an error occurred while loading the content.

Problem with getItem() on a menu

Expand Messages
  • meardon22
    Hello, I have tried this code . It s work, but I can t use the function getItem(), it s
    Message 1 of 2 , Oct 31, 2008
    • 0 Attachment
      Hello,

      I have tried this code. It's work, but I can't use the function getItem(), it's return undefined.

      [code]
      var oFieldContextMenu = new YAHOO.widget.ContextMenu(
                  "fieldcontextmenu",
                  {
                      trigger: "mainview",
                      itemdata: oFieldContextMenuItemData,
                      lazyload: true,
                      effect: { effect:YAHOO.widget.ContainerEffect.FADE, duration:0.25 }    
                  }
              );

      window.alert(oFieldContextMenu.getItem(0));  // Return 'undefined'
      [/code]

      How do I get this ?

      Thanks
    • Todd Kloots
      meardon - The reason that oFieldContextMenu.getItem(0) is returning undefined is because you have specified that the content of the ContextMenu instance be
      Message 2 of 2 , Dec 9, 2008
      • 0 Attachment
        "meardon" - 

        The reason that "oFieldContextMenu.getItem(0)" is returning undefined is because you have specified that the content of the ContextMenu instance be lazy loaded:

        var oFieldContextMenu = new YAHOO.widget.ContextMenu(
                    "fieldcontextmenu",
                    {
                        trigger: "mainview",
                        itemdata: oFieldContextMenuItemData,
                        lazyload: true, // YOU ARE USING LAZYLOAD
                        effect: { effect:YAHOO.widget.ContainerEffect.FADE, duration:0.25 }     
                    }
                );

        When you set the "lazyload" configuration property to "true" none of the MenuItems are created until the ContextMenu is initially rendered - which occurs the first time it is requested via the firing of the "contextmenu" event (by a right click).  Therefore, if you need programmatic access to items, you should register a "render" event listener and access those items within the scope of that listener.

        oFieldContextMenu.subscribe("render", function () {

        if (this.getItems() > 0) {

        window.alert(this.getItem( 0));

        }

        });

        On Oct 31, 2008, at 4:53 AM, meardon22 wrote:

        Hello,

        I have tried this code. It's work, but I can't use the function getItem(), it's return undefined.

        [code]
        var oFieldContextMenu = new YAHOO.widget. ContextMenu(
                    "fieldcontextmenu" ,
                    {
                        trigger: "mainview",
                        itemdata: oFieldContextMenuIt emData,
                        lazyload: true,
                        effect: { effect:YAHOO. widget.Container Effect.FADE, duration:0.25 }     
                    }
                );

        window.alert( oFieldContextMen u.getItem( 0));  // Return 'undefined'
        [/code]

        How do I get this ?

        Thanks


      Your message has been successfully submitted and would be delivered to recipients shortly.