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

Replacing the content of a Button's Menu

Expand Messages
  • George
    Hi, Trying to replace the content of a button s menu from an event inside of another button menu was unsuccessful. I create the 2 menus like below. var
    Message 1 of 2 , Dec 10, 2009
    • 0 Attachment
      Hi,

      Trying to replace the content of a button's menu from an event inside  of another button menu was unsuccessful. I create the 2 menus like below.

      var oMenuButton2 = new YAHOO.widget.Button("menubutton2",{ type: "menu", menu: "agentsmenu" });
      oMenuButton2.getMenu().subscribe("click", onMenuclickAgent);

      var oMenuButton3 = new YAHOO.widget.Button("menubutton3",{ type: "menu", menu: "superagentsmenu" });
      oMenuButton3.getMenu().subscribe("click", onMenuclickSuperAgent);


      I am trying to change the content of oMenuButton2 menu, from the a click event like below, but it does not work. What may be wrong ?

      var onMenuclickSuperAgent = function (p_sType, p_aArgs) {

      var oEvent = p_aArgs[0],    //    DOM event

      oMenuItem = p_aArgs[1];    //    MenuItem instance that was the
      //    target of the event
          if (oMenuItem) {

                          var oMenuAgent = oMenuButton2.getMenu();
                          oMenuAgent.clearContent();
                          oMenuAgent.render();
                          oMenuAgent.itemData = menuitems;

           }

      };
    • George Papaioannou
      I changed the previous code with the code below and partially is working. The problem is that in case the oMenuAgent menu is not renderer (the else part) the
      Message 2 of 2 , Dec 10, 2009
      • 0 Attachment
        I changed the previous code with the code below and partially is working. The problem is that in case the oMenuAgent menu is not renderer (the else part) the new item is added to the current items and not replacing the previous content. Any ideas ?

                var onMenuclickSuperAgent = function (p_sType, p_aArgs) {

                    var oEvent = p_aArgs[0],    //    DOM event

                        oMenuItem = p_aArgs[1];    //    MenuItem instance that was the
                                                //    target of the event

                    if (oMenuItem) {

                        var oMenuAgent = oMenuButton2.getMenu();

                        //  determine if the Button's Menu has been rendered.
                        if (YAHOO.util.Dom.inDocument(oMenuButton2.getMenu().element)) {


                            oMenuAgent.clearContent();
                            oMenuAgent.addItems([{ text: "Four", value: 4 }]);
                            oMenuAgent.render();
                            alert("ok1");
                         } else {

                           oMenuAgent.itemData =  [{ text: "Four", value: 4 },{ text: "Five", value: 5 }];
                           alert("ok2");
                         }
                 }
        };

        --- Στις Παρ., 11/12/09, ο/η George <sdancer75@...> έγραψε:

        Από: George <sdancer75@...>
        Θέμα: [ydn-javascript] Replacing the content of a Button's Menu
        Προς: ydn-javascript@yahoogroups.com
        Ημερομηνία: Παρασκευή, 11 Δεκέμβριος 2009, 0:10

         

        Hi,

        Trying to replace the content of a button's menu from an event inside  of another button menu was unsuccessful. I create the 2 menus like below.

        var oMenuButton2 = new YAHOO.widget. Button("menubutt on2",{ type: "menu", menu: "agentsmenu" });
        oMenuButton2. getMenu() .subscribe( "click", onMenuclickAgent) ;

        var oMenuButton3 = new YAHOO.widget. Button("menubutt on3",{ type: "menu", menu: "superagentsmenu" });
        oMenuButton3. getMenu() .subscribe( "click", onMenuclickSuperAge nt);


        I am trying to change the content of oMenuButton2 menu, from the a click event like below, but it does not work. What may be wrong ?

        var onMenuclickSuperAge nt = function (p_sType, p_aArgs) {

        var oEvent = p_aArgs[0],    //    DOM event

        oMenuItem = p_aArgs[1];    //    MenuItem instance that was the
        //    target of the event
            if (oMenuItem) {

                            var oMenuAgent = oMenuButton2. getMenu() ;
                            oMenuAgent.clearCon tent();
                            oMenuAgent.render( );
                            oMenuAgent.itemData = menuitems;

             }

        };



        Χρησιμοποιείτε Yahoo!
        Βαρεθήκατε τα ενοχλητικά μηνύ ματα (spam); Το Yahoo! Mail διαθέτει την καλύτερη δυνατή προστασία κατά των ενοχλητικών μηνυμάτων
        http://login.yahoo.com/config/mail?.intl=gr
      Your message has been successfully submitted and would be delivered to recipients shortly.