(() => {
function init({ moduleId }) {
const sxc = $2sxc(moduleId);
const poetsSvc = sxc.data('Poets');
poetsSvc.getAll().then((poets) => {
displayPoets(poets);
poetsSvc.getOne(poets[0].Id).then((poet) => console.log(`Queried poet using .getOne(): ${poet}`));
});
}
function displayPoets(poets) {
Array.prototype.forEach.call(poets.reverse(), (poet, poetIndex) => {
if (poetIndex >= 3) return
let tr = document.createElement('tr')
addField(tr, poet.Name);
addField(tr, new Date(poet.BirthDate).toLocaleDateString());
addField(tr, poet.Poems);
document.querySelector('#example-content > tbody').appendChild(tr)
});
}
function addField(tr, text) {
let td = document.createElement('td')
td.innerText = text
tr.appendChild(td)
}
const sDT = window.sxcDataTutorial200 = window.sxcDataTutorial200 || {};
sDT.init = sDT.init || init;
})();