Question

I currently load my dyna tree from using JSON as so:

$(document).ready(function () {

  // Loads tree
  $("#TreeManGrp").dynatree({
    initAjax: {
      url: "/Terminals/Refresh/"
    },
    onActivate: function (node) {
      if (node.data.href) {
        window.open(node.data.href, "_self");
      }
    },
    persist: true,
    noLink: false,
    fx: { height: "toggle", duration: 200 }

  });
});

I need to get the activated node if there is one after the tree is loaded into the dom. The documentation suggests using this approach:

  // Loads tree
  $("#TreeManGrp").dynatree({
    initAjax: {
      url: "/Terminals/Refresh/",
      success: function (data) {
        alert("hi");
      }
    },
    onActivate: function (node) {
      if (node.data.href) {
        window.open(node.data.href, "_self");
      }
    },
    persist: true,
    noLink: false,
    fx: { height: "toggle", duration: 200 }
  });

But this doesnt work either. Looing through the dynatree source file it says:

  if (ajaxOpts.success) {
        this.logWarning("initAjax: success callback is ignored; use onPostInit instead.");
      } 

My question is does anyone know how to use onPostInit instead?

Was it helpful?

Solution

I figured it out:

  // Loads tree
  $("#TreeManGrp").dynatree({
    initAjax: {
      url: "/Terminals/Refresh/"
    },
    onActivate: function (node) {
      if (node.data.href) {
        window.open(node.data.href, "_self");
      } else {
        ContextButtonSwitch(node.data.type, node.data.itemId);
      }


    },
    persist: true,
    noLink: false,
    fx: { height: "toggle", duration: 200 },
    onPostInit: function (isReloading, isError) {
      var node = $("#TreeManGrp").dynatree("getActiveNode");
      if (node) {
        ContextButtonSwitch(node.data.type, node.data.itemId);
      }
    }
  });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top