2

我目前使用 JSON 加载我的动态树,如下所示:

$(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 }

  });
});

如果在将树加载到 dom 后有一个节点,我需要获取激活的节点。文档建议使用这种方法:

  // 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 }
  });

但这也不起作用。浏览 dynatree 源文件,它说:

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

我的问题是有人知道如何改用 onPostInit 吗?

4

1 回答 1

3

我想到了:

  // 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);
      }
    }
  });
于 2013-02-11T12:32:19.980 回答