2013-02-11 65 views
2

我目前使用JSON作为使加载我DYNA树:敦南树AJAX负荷回调

$(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源Looing文件,它说:

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

我的问题是没有人知道如何使用代替onPostInit?

回答

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