Search code examples
javascriptjqueryjquery-dynatree

can't use addChild method


I'm using the dynatree plugin for the first time, and I'm trying to add nodes dynamically. My code is below:

function DrawTree() {
 var names = GetChildName();  
 var rootNode = $("#ProcessRoleTree").dynatree("getRoot");
 var childNode = rootNode.addChild({ title: names[0].Name });
}

On runtime an error displays

Microsoft JScript runtime error: Object doesn't support this property or method

Am I missing something ?? I have verify that i included needed libraries :

<script src="Jquery/jquery/jquery.js" type="text/javascript"></script>
<script src="Jquery/jquery/jquery-ui.custom.js" type="text/javascript"></script>
<script src="Jquery/jquery/jquery.cookie.js" type="text/javascript"></script>

<link href="Jquery/src/skin-vista/ui.dynatree.css" rel="stylesheet" type="text/css" />
<script src="Jquery/src/jquery.dynatree.js" type="text/javascript"></script>

Thanks in advance!


Solution

  • This might not be your problem, but it is worth a shot. Sometimes, when using jQuery with other libraries, you can run into conflicts with conflicting code. jQuery uses the $ sign as a shortcut for jQuery. The dynatree library also use the dollar sign for their functions.

    I ran into this problem when implementing my tree and this is how I fixed it. As you can see, I replaced all '$' with 'jQuery'.

    <script type="text/javascript">
    jQuery.noConflict();
    
    function DrawTree() {
        var names = GetChildName();
        jQuery("#ProcessRoleTree").dynatree();
    
        var rootNode = jQuery("#ProcessRoleTree").dynatree("getRoot");
    
        //Try adding a key
        var childNode = rootNode.addChild({ title: names[0].Name, key: "001" });
    }
    </script>