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

Problem in treeview when using YAHOO.util.Connect.asyncRequest

Expand Messages
  • ÎÏÅ£
    it can t work when it work i must check twice to see the child node. but it had loaded xml,when the first time i check then farther node. This is the
    Message 1 of 2 , Feb 1, 2007
    • 0 Attachment
      it can't work

      when it work i must check twice to see the child node.

      but it had loaded xml,when the first time i check then farther node.

      This is the javascript

      <script>
      YAHOO.namespace("example");
      YAHOO.example.treeExample = function() {
      var tree;
      function successHandler(o){
      var node = o.argument.node;
      var xmlroot = o.responseXML.documentElement;
      var onum = xmlroot.getElementsByTagName('num')[0].firstChild.nodeValue;
      for (var i=0; i<onum; i++) {
      var label =
      xmlroot.getElementsByTagName('label')[i].firstChild.nodeValue;
      var id = xmlroot.getElementsByTagName('id')[i].firstChild.nodeValue;
      var url = xmlroot.getElementsByTagName('url')[i].firstChild.nodeValue;
      var newNode = new YAHOO.widget.TextNode({ label:label, id:id },
      node, false);
      // if (url!="") {
      // newNode.onLabelClick = onLabelClick(url);
      // }
      }
      document.getElementById('info').innerHTML = "OK";
      }
      function failureHandler(o){
      document.getElementById('info').innerHTML = "error";
      }
      function onLabelClick(url) {
      window.location = url;
      }
      function loadNodeData(node, fnLoadComplete) {
      var sUrl = "made_tree_xml.php?id=" + node.data.id;
      //***********************************
      // here load xml and the php query by node id.
      //***********************************
      var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, {
      success:successHandler, failure:failureHandler, argument:{node:node} });
      //***********************************
      // here use "argument:{node:node}" to post the object
      //***********************************

      fnLoadComplete();
      }
      function buildTree() {
      tree = new YAHOO.widget.TreeView("treeContainer");
      tree.setDynamicLoad(loadNodeData, 1);
      var root = tree.getRoot();
      var tmpNode1 = new YAHOO.widget.TextNode({ label: "mylabel1",
      id:"200701141016563626136752733278164" }, root, false);
      var tmpNode2 = new YAHOO.widget.TextNode({ label: "mylabel2",
      id:"20070114101656362613675273327816403" }, root, false);
      var tmpNode3 = new YAHOO.widget.TextNode({ label: "mylabel3",
      id:"200701141016563626136752733278164070204" }, root, false);
      var tmpNode4 = new YAHOO.widget.TextNode({ label: "mylabel4",
      id:"200701141016563626136752733278164070204" }, root, false);
      var tmpNode5 = new YAHOO.widget.TextNode({ label: "mylabel5",
      id:"200701141016563626136752733278164070204" }, root, false);
      tree.draw();
      }
      return {
      init: function() {
      buildTree();
      }
      }
      } ();
      YAHOO.util.Event.addListener(window, "load",
      YAHOO.example.treeExample.init, YAHOO.example.treeExample, true)
      </script>

      this is the xml made by made_tree_xml.php?id=xxxx

      <tree>
      <num>5</num>
      <note>
      <label>title x</label>
      <id>2007011410165636261367527332781640306</id>
      <url>present.php?id=2007011410165636261367527332781640306</url>
      </note><note>
      <label>title y</label>
      <id>2007011410165636261367527332781640302</id>
      <url/>
      </note>
      <note>
      <label>title z</label>
      <id>2007011410165636261367527332781640303</id>
      <url/>
      </note>
      <note>
      <label>title a</label>
      <id>2007011410165636261367527332781640304</id>
      <url/>
      </note>
      <note>
      <label>title word</label>
      <id>2007011410165636261367527332781640305</id>
      <url/>
      </note>
      </tree>
    • Joseph F. Douglas
      I had the same problem. I did find a solution in one of the messages but can t give credit as I can t find it again. However, the loadComplete function
      Message 2 of 2 , Mar 11 11:43 AM
      • 0 Attachment
        I had the same problem. I did find a solution in one of the messages
        but can't give credit as I can't find it again. However, the
        loadComplete function reference must be passed through the callback
        object as the async request returns the information too late for the
        loadComplete to catch it in the yui TreeView ynamic load example.

        A solution can be seen at message# 10595

        I hope you can make sense of it.
      Your message has been successfully submitted and would be delivered to recipients shortly.