Last active
November 28, 2016 00:08
-
-
Save droberts-sea/41c26e15772b2c6986a765d002a25e82 to your computer and use it in GitHub Desktop.
Ada C6 Backbone Views Checkin 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import $ from 'jquery'; | |
import Backbone from 'backbone'; | |
var taskData = [ | |
{ | |
title: 'Mow the lawn', | |
description: 'Must be finished before BBQ on Sat afternoon' | |
}, { | |
title: 'Go to the Bank', | |
description: 'Need to make a transfer' | |
}, { | |
title: 'Tune the Piano', | |
description: 'High C is missing or something???' | |
} | |
]; | |
var TaskView = Backbone.View.extend({ | |
initialize: function(options) { | |
this.task = options.task; | |
}, | |
render: function() { | |
var html = '<li class="task">'; | |
html += '<h2>' + this.task.title + '</h2>'; | |
html += '<p>' + this.task.description + '</p>'; | |
html += '</li>'; | |
this.$el.html($(html)); | |
// Enable chained calls | |
return this; | |
} | |
}); | |
$(document).ready(function() { | |
var taskListElement = $('.task-list'); | |
var cardList = [] | |
taskData.forEach(function(task) { | |
var card = new TaskView({task: task}); | |
cardList.push(card); | |
taskListElement.append(card.render().$el); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment