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

Menu driven by dynamic callback

Expand Messages
  • an0n73
    Hi, I d like to create a MenuBar in which the subMenu s within each menu are driven by a connection manager callback function. My experience with YUI isn t
    Message 1 of 6 , Dec 8, 2009
    • 0 Attachment
      Hi,

      I'd like to create a MenuBar in which the subMenu's within each menu are driven by a connection manager callback function.
      My experience with YUI isn't extensive so I'm hoping for some guidance.

      Taking one of the examples, I have the following which works:

      Markup is:
      ...
      <div class="bd"><ul class="first-of-type">
      <li class="yuimenubaritem first-of-type">
      <a class="yuimenubaritemlabel" href="#communication">Communication</a></li>
      ...
      and the javascript is:
      ...
      var oMenuBar = new ...
      var data = "[{id: 'communication',itemdata[{text:'360',url:....etc}]";
      var aSubmenuData = eval(data);
      oMenuBar.subscribe("beforeRender", function() { .....
      <rest of example>

      What I'm think is that what I need is to basically replace the line
      var data = "[{id: 'communiction' ....
      with a callback function so that this variable data is populated from the results of the callback function.

      My questions are:
      - would this work?
      - if so, how do I setup the callback function in high level terms, would the function be within the existing onContentReady event or external and if so how do I assign the Response object data back to my variable?

      Any help would be appreciated.

      Thanks
    • Todd Kloots
      Here is how I would structure your code for creating a menubar with submenus that are built from data from XHR:
      Message 2 of 6 , Dec 9, 2009
      • 0 Attachment
        Here is how I would structure your code for creating a menubar with
        submenus that are built from data from XHR:

        http://yuiblog.com/sandbox/yui/v280/examples/menu/async-menu.html

        - Todd


        On Dec 8, 2009, at 10:31 PM, an0n73 wrote:

        > Hi,
        >
        > I'd like to create a MenuBar in which the subMenu's within each menu
        > are driven by a connection manager callback function.
        > My experience with YUI isn't extensive so I'm hoping for some
        > guidance.
        >
        > Taking one of the examples, I have the following which works:
        >
        > Markup is:
        > ...
        > <div class="bd"><ul class="first-of-type">
        > <li class="yuimenubaritem first-of-type">
        > <a class="yuimenubaritemlabel" href="#communication">Communication</
        > a></li>
        > ...
        > and the javascript is:
        > ...
        > var oMenuBar = new ...
        > var data = "[{id: 'communication',itemdata[{text:'360',url:....etc}]";
        > var aSubmenuData = eval(data);
        > oMenuBar.subscribe("beforeRender", function() { .....
        > <rest of example>
        >
        > What I'm think is that what I need is to basically replace the line
        > var data = "[{id: 'communiction' ....
        > with a callback function so that this variable data is populated
        > from the results of the callback function.
        >
        > My questions are:
        > - would this work?
        > - if so, how do I setup the callback function in high level terms,
        > would the function be within the existing onContentReady event or
        > external and if so how do I assign the Response object data back to
        > my variable?
        >
        > Any help would be appreciated.
        >
        > Thanks
        >
        >
        >
        >
        >
        >
        > ------------------------------------
        >
        > Yahoo! Groups Links
        >
        >
        >
      • an0n73
        Thanks Todd, just what I was looking for to get me going.
        Message 3 of 6 , Dec 9, 2009
        • 0 Attachment
          Thanks Todd, just what I was looking for to get me going.

          --- In ydn-javascript@yahoogroups.com, Todd Kloots <kloots@...> wrote:
          >
          > Here is how I would structure your code for creating a menubar with
          > submenus that are built from data from XHR:
          >
          > http://yuiblog.com/sandbox/yui/v280/examples/menu/async-menu.html
          >
          > - Todd
          >
          >
          > On Dec 8, 2009, at 10:31 PM, an0n73 wrote:
          >
          > > Hi,
          > >
          > > I'd like to create a MenuBar in which the subMenu's within each menu
          > > are driven by a connection manager callback function.
          > > My experience with YUI isn't extensive so I'm hoping for some
          > > guidance.
          > >
          > > Taking one of the examples, I have the following which works:
          > >
          > > Markup is:
          > > ...
          > > <div class="bd"><ul class="first-of-type">
          > > <li class="yuimenubaritem first-of-type">
          > > <a class="yuimenubaritemlabel" href="#communication">Communication</
          > > a></li>
          > > ...
          > > and the javascript is:
          > > ...
          > > var oMenuBar = new ...
          > > var data = "[{id: 'communication',itemdata[{text:'360',url:....etc}]";
          > > var aSubmenuData = eval(data);
          > > oMenuBar.subscribe("beforeRender", function() { .....
          > > <rest of example>
          > >
          > > What I'm think is that what I need is to basically replace the line
          > > var data = "[{id: 'communiction' ....
          > > with a callback function so that this variable data is populated
          > > from the results of the callback function.
          > >
          > > My questions are:
          > > - would this work?
          > > - if so, how do I setup the callback function in high level terms,
          > > would the function be within the existing onContentReady event or
          > > external and if so how do I assign the Response object data back to
          > > my variable?
          > >
          > > Any help would be appreciated.
          > >
          > > Thanks
          > >
          > >
          > >
          > >
          > >
          > >
          > > ------------------------------------
          > >
          > > Yahoo! Groups Links
          > >
          > >
          > >
          >
        • an0n73
          Hi Todd, One more question... I ve changed your sURL page to my own getMenuData.jsp page and all this page contains as a test is what I believe to be the
          Message 4 of 6 , Dec 9, 2009
          • 0 Attachment
            Hi Todd,

            One more question...

            I've changed your sURL page to my own getMenuData.jsp page and all this page contains as a test is what I believe to be the correct format of a JSON string however it clearly isn't correct as when it's returned and the JSON.parse method is used on the reponseText it throws an error.
            I've tried various string formats but none of them work:
            "[{text:'Test1',url:'www.d.com'}]"
            or
            "[{id: 'communication',itemdata:[{text:'Test1',url:'www.d.com'}]}]"

            Can you tell me what format is expected back in the responseText?

            Thanks

            --- In ydn-javascript@yahoogroups.com, "an0n73" <an0n73@...> wrote:
            >
            > Hi,
            >
            > I'd like to create a MenuBar in which the subMenu's within each menu are driven by a connection manager callback function.
            > My experience with YUI isn't extensive so I'm hoping for some guidance.
            >
            > Taking one of the examples, I have the following which works:
            >
            > Markup is:
            > ...
            > <div class="bd"><ul class="first-of-type">
            > <li class="yuimenubaritem first-of-type">
            > <a class="yuimenubaritemlabel" href="#communication">Communication</a></li>
            > ...
            > and the javascript is:
            > ...
            > var oMenuBar = new ...
            > var data = "[{id: 'communication',itemdata[{text:'360',url:....etc}]";
            > var aSubmenuData = eval(data);
            > oMenuBar.subscribe("beforeRender", function() { .....
            > <rest of example>
            >
            > What I'm think is that what I need is to basically replace the line
            > var data = "[{id: 'communiction' ....
            > with a callback function so that this variable data is populated from the results of the callback function.
            >
            > My questions are:
            > - would this work?
            > - if so, how do I setup the callback function in high level terms, would the function be within the existing onContentReady event or external and if so how do I assign the Response object data back to my variable?
            >
            > Any help would be appreciated.
            >
            > Thanks
            >
          • Todd Kloots
            All keys need to be strings. For example: [{ id : communication , itemdata : [ { text : Test1 , url : www.d.com } ] }] For more:
            Message 5 of 6 , Dec 9, 2009
            • 0 Attachment
              All keys need to be strings. For example:

              [{ "id": "communication", "itemdata": [ { "text": "Test1", "url": "www.d.com
              " } ] }]

              For more: http://developer.yahoo.com/yui/json/#about

              - Todd

              On Dec 9, 2009, at 3:42 PM, an0n73 wrote:

              > Hi Todd,
              >
              > One more question...
              >
              > I've changed your sURL page to my own getMenuData.jsp page and all
              > this page contains as a test is what I believe to be the correct
              > format of a JSON string however it clearly isn't correct as when
              > it's returned and the JSON.parse method is used on the reponseText
              > it throws an error.
              > I've tried various string formats but none of them work:
              > "[{text:'Test1',url:'www.d.com'}]"
              > or
              > "[{id: 'communication',itemdata:[{text:'Test1',url:'www.d.com'}]}]"
              >
              > Can you tell me what format is expected back in the responseText?
              >
              > Thanks
              >
              > --- In ydn-javascript@yahoogroups.com, "an0n73" <an0n73@...> wrote:
              >>
              >> Hi,
              >>
              >> I'd like to create a MenuBar in which the subMenu's within each
              >> menu are driven by a connection manager callback function.
              >> My experience with YUI isn't extensive so I'm hoping for some
              >> guidance.
              >>
              >> Taking one of the examples, I have the following which works:
              >>
              >> Markup is:
              >> ...
              >> <div class="bd"><ul class="first-of-type">
              >> <li class="yuimenubaritem first-of-type">
              >> <a class="yuimenubaritemlabel" href="#communication">Communication</
              >> a></li>
              >> ...
              >> and the javascript is:
              >> ...
              >> var oMenuBar = new ...
              >> var data = "[{id:
              >> 'communication',itemdata[{text:'360',url:....etc}]";
              >> var aSubmenuData = eval(data);
              >> oMenuBar.subscribe("beforeRender", function() { .....
              >> <rest of example>
              >>
              >> What I'm think is that what I need is to basically replace the line
              >> var data = "[{id: 'communiction' ....
              >> with a callback function so that this variable data is populated
              >> from the results of the callback function.
              >>
              >> My questions are:
              >> - would this work?
              >> - if so, how do I setup the callback function in high level terms,
              >> would the function be within the existing onContentReady event or
              >> external and if so how do I assign the Response object data back to
              >> my variable?
              >>
              >> Any help would be appreciated.
              >>
              >> Thanks
              >>
              >
              >
              >
              >
              > ------------------------------------
              >
              > Yahoo! Groups Links
              >
              >
              >
            • an0n73
              I ve found that if I replace the JSON.parse(...) method with eval(...) then my it all works fine for a format of: [{text: Test1 ,url: www.d.com }] Reading
              Message 6 of 6 , Dec 9, 2009
              • 0 Attachment
                I've found that if I replace the JSON.parse(...) method with
                eval(...) then my it all works fine for a format of:
                "[{text:'Test1',url:'www.d.com'}]"

                Reading the JSON information, I'm informed that using eval(..) is unsafe but it's the only thing that works. How can I get it to work without the use of eval(..)?

                --- In ydn-javascript@yahoogroups.com, "an0n73" <an0n73@...> wrote:
                >
                > Hi Todd,
                >
                > One more question...
                >
                > I've changed your sURL page to my own getMenuData.jsp page and all this page contains as a test is what I believe to be the correct format of a JSON string however it clearly isn't correct as when it's returned and the JSON.parse method is used on the reponseText it throws an error.
                > I've tried various string formats but none of them work:
                > "[{text:'Test1',url:'www.d.com'}]"
                > or
                > "[{id: 'communication',itemdata:[{text:'Test1',url:'www.d.com'}]}]"
                >
                > Can you tell me what format is expected back in the responseText?
                >
                > Thanks
                >
                > --- In ydn-javascript@yahoogroups.com, "an0n73" <an0n73@> wrote:
                > >
                > > Hi,
                > >
                > > I'd like to create a MenuBar in which the subMenu's within each menu are driven by a connection manager callback function.
                > > My experience with YUI isn't extensive so I'm hoping for some guidance.
                > >
                > > Taking one of the examples, I have the following which works:
                > >
                > > Markup is:
                > > ...
                > > <div class="bd"><ul class="first-of-type">
                > > <li class="yuimenubaritem first-of-type">
                > > <a class="yuimenubaritemlabel" href="#communication">Communication</a></li>
                > > ...
                > > and the javascript is:
                > > ...
                > > var oMenuBar = new ...
                > > var data = "[{id: 'communication',itemdata[{text:'360',url:....etc}]";
                > > var aSubmenuData = eval(data);
                > > oMenuBar.subscribe("beforeRender", function() { .....
                > > <rest of example>
                > >
                > > What I'm think is that what I need is to basically replace the line
                > > var data = "[{id: 'communiction' ....
                > > with a callback function so that this variable data is populated from the results of the callback function.
                > >
                > > My questions are:
                > > - would this work?
                > > - if so, how do I setup the callback function in high level terms, would the function be within the existing onContentReady event or external and if so how do I assign the Response object data back to my variable?
                > >
                > > Any help would be appreciated.
                > >
                > > Thanks
                > >
                >
              Your message has been successfully submitted and would be delivered to recipients shortly.