Marking An Item As Complete
Goals
Resumen
Pasos
Step 1
$('#list').on('click', '.complete-button', function(event) { alert('trying to complete an item!') })Step 2
var item = $(event.target).parent() var isItemCompleted = item.hasClass('completed') var itemId = item.attr('data-id') alert('clicked item ' + itemId + ', which has completed currently set to ' + isItemCompleted)Step 3
var updateRequest = $.ajax({ type: 'PUT', url: "https://listalous.herokuapp.com/lists/YOUR-LIST-NAME-HERE/items/" + itemId, data: { completed: !isItemCompleted } })Step 4
updateRequest.done(function(itemData) { if (itemData.completed) { item.addClass('completed') } else { item.removeClass('completed') } })
Explicación
$('#list').on('click', '.complete-button', function(event) { var item = $(event.target).parent() var isItemCompleted = item.hasClass('completed') var itemId = item.attr('data-id') var updateRequest = $.ajax({ type: 'PUT', url: "https://listalous.herokuapp.com/lists/YOUR-LIST-NAME-HERE/items/" + itemId, data: { completed: !isItemCompleted } }) updateRequest.done(function(itemData) { if (itemData.completed) { item.addClass('completed') } else { item.removeClass('completed') } }) })
Next Step:
Go on to Deploying Your Site