I am attempting to load data from a database with JS to store it in an unordered list in my HTML file. I have another script file that modifies this unordered list with jQuery once the jQuery constructor is called. Below is an overview of the code I have so far:
function init() {
console.log("init");
function fb()
{
//get data point from database
var x = document.createElement("LI");
var t = document.createTextNode(/*data from database*/);
x.appendChild(t);
document.getElementById("unordered_list").appendChild(x);
}
$('.easy-tree').EasyTree({
addable: true,
editable: true,
deletable: true
});
}
window.onload = init();
The problem I am running into is that the jQuery constructor gets called before I finish updating the unordered list with the correct data from the database. What happens now is that the empty list gets formatted with the jQuery, and then the database data is added in unformatted. The call to the database within the fb() method seems to slow the method down, and allow the constructor to be called before it finishes.
I need to find a way to make sure the fb method is completely done storing items in the unordered list before I call the jQuery constructor to format the data. How could I make sure that happens?