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

setDynamicLoad

Expand Messages
  • tx_scottwalter
    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
    Message 1 of 2 , Feb 14, 2006
    • 0 Attachment
      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();
      }

      So in here I will make my ajax call which lets say I will have a call
      back method called "getData()". How would "getData()" get access to
      the current node to add the subnodes to?

      thanks, scott.
    • 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 2 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.