Skip to content

Instantly share code, notes, and snippets.

@aguileraq
Created January 17, 2019 00:41
Show Gist options
  • Save aguileraq/c03323898f09988ddad6deca75e4bb67 to your computer and use it in GitHub Desktop.
Save aguileraq/c03323898f09988ddad6deca75e4bb67 to your computer and use it in GitHub Desktop.
class UI {
static displayElements() {
//let elements = Store.getElements().then(r => {return r});
let elements = Store.getElements()
.then((data)=> {return data});
console.log(elements);
elements.forEach(function(element) {
UI.addElementsToDom(element)
});
}
static addElementsToDom(element) {
const list = document.querySelector('#element-list');
const a = document.createElement('a');
a.classList.add('list-group-item list-group-item-action');
a.setAttribute("href","#");
a.innerHTML = `${element.name}`;
list.appendChild(row);
}
}
// Store Class: Handles Storage
class Store {
static async getElements() {
let url = `https://carlos.rhinox.local/assets/js/elements.json`;
let response = await fetch(url);
let data = await response.json();
return data;
}
}
async function fetchFormBuilder(){
const data = await Store.getElements();
UI.displayElements(data);
}
// Event: Display Elements
document.addEventListener('DOMContentLoaded', fetchFormBuilder);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment