I’m trying to build a tree of LI/UL elements from an interal object I have in javascript. Making the top level elements works fine, but then recursivley building the child elements seems to be causing me problems.
in the code below #DynaTree is the UL element that is the root of my tree. tv is my object that represents the tree – I’ve actually stubbed out the child creation code to something more simple just to get it working. You can also see the commented out line where I tried a different approach. In either case, I get no error, but I never see the child elements appended to the first level of objects.
for(i = 0; i < tv.getSize();i++){
var t = tv.getTaskAt(i);
var newul = $("<ul>" + t.TaskName + "(" + t.GUID + ")</ul>");
makeChildren(newul);
$("#DynaTree").append(newul);
}
function makeChildren(el){
var randomnumber=Math.floor(Math.random()*11);
console.log("Making Children Elements " + randomnumber);
for(var i = 0; i < randomnumber;i++){
var newElement = $("<ul>New Element</ul");
/************************
Neither one of these methods works!
***********************/
//$("#DynaTree", el).append(newElement);
el.append(newElement);
}
}
`
Feels like I’m missing something obvious. Any help much appreciated.
-ace
You are missing the closing
>at the end of creating the new element, should read…