2017-01-25 5 views
1

J'utilisais le script - laissez ci-dessous pour ajouter un noeud à un arbre dhtmlx. J'essayais d'obtenir l'ID en utilisant getSelectedItemId() à partir d'un arbre DHTMLX. Et j'ai rencontré cette erreur.Uncaught TypeError: Impossible d'exécuter 'appendChild' sur 'Node': le paramètre 1 n'est pas de type 'Node'.

<script> 
var xmlDoc 
var xhttp = new XMLHttpRequest(); 
xhttp.onreadystatechange = function() { 
    if (this.readyState == 4 && this.status == 200) { 
     xmlDoc = this; 
    } 
}; 
xhttp.open("GET", "data/treeStruct.xml", true); 
xhttp.send(); 

    var myTree; 

function append(id){ 
       var x; 
       var ed1=document.getElementById('ed1').value; 
       //alert(id); 
       xmlDoc = xmlDoc.responseXML; 
       var newEle = xmlDoc.createElement(id); 
       newEle.appendChild(ed1); 
       document.getElementsByTagName("tree")[0].appendChild(newEle); 
      } 
</script>   

Répondre

0

DHTMLX Tree a sa propre API pour ajouter des nœuds. Vous n'avez pas besoin d'interagir directement avec HTML. Il suffit d'utiliser le code suivant comme

//to add a new item to the tree 
tree.insertNewChild(0,1,"tree") 
tree.insertNewChild(1,2,"child") 
//parent id, id, text 

Aussi, vérifiez l'extrait http://snippet.dhtmlx.com/320fe781a