Loading Items
Goals
Overview
Steps
Step 1
var loadRequest = $.ajax({ type: 'GET', url: "https://listalous.herokuapp.com/lists/YOUR-LIST-NAME-HERE/" })Step 2
loadRequest.done(function(dataFromServer) { var itemsData = dataFromServer.items itemsData.forEach(function(itemData) { addItemToPage(itemData) }) })
Explanation
var itemTemplate = $('#templates .item') var list = $('#list') var addItemToPage = function(itemData) { var item = itemTemplate.clone() item.attr('data-id',itemData.id) item.find('.description').text(itemData.description) if(itemData.completed) { item.addClass('completed') } list.append(item) } var loadRequest = $.ajax({ type: 'GET', url: "https://listalous.herokuapp.com/lists/YOUR-LIST-NAME-HERE/" }) loadRequest.done(function(dataFromServer) { var itemsData = dataFromServer.items itemsData.forEach(function(itemData) { addItemToPage(itemData) }) })
Next Step:
Go on to Adding An Item