我目前正在使用JSON加载我的dyna树:
$(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?
答案 0 :(得分: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);
}
}
});