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

Re: [ydn-javascript] setDynamicLoad

Expand Messages
  • Adam Moore
    ... Hi Scott, You need to pass the node and callback as arguments to the connection utility: function loadDataForNode(node, onCompleteCallback) { var url =
    Message 1 of 2 , Feb 14, 2006
    • 0 Attachment
      On Tue, Feb 14, 2006 at 05:42:08PM -0000, tx_scottwalter wrote:
      > Hi,
      >
      > I'm trying to use the Tree control via an Ajax call. I have this:
      >
      > tree.setDynamicLoad(loadDataForNode)
      >
      > I understand that when a node is clicked this function will be called.
      > My question is how do I get the tree to load on a completion of an
      > Ajax call? I see from the docs they have something like this:
      >
      > function loadDataForNode(node, onCompleteCallback) {
      > // Be sure to notify the TreeView component when the data load is
      > complete
      > onCompleteCallback();
      > }

      Hi Scott,

      You need to pass the node and callback as arguments to the connection
      utility:

      function loadDataForNode(node, onCompleteCallback) {
      var url = "http://yourhost.com/yourpage";
      var transInfo = {
      success: handleResponse,
      argument: { node: node, callback: onCompleteCallback }
      };

      YAHOO.util.Connect.asyncRequest( 'GET', url, transInfo, null );
      }

      Then you can use that reference to create new nodes with the data you fetched:

      function handleResponse(o) {

      if (o && o.responseText && o.responseText.length > 1) {
      // Assumes the response is a comma separated list of node labels
      var labels = o.responseText.split(",");

      for ( var i = 0; i < labels.length; i++ ) {

      // Get the node we wish to update from the Connect response
      var node = o.argument.node;

      // Create a new text node
      n = new YAHOO.widget.TextNode(labels[i], node, false);
      }
      }

      // Notify the tree that we are done processing the data
      o.argument.callback();

      }


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