Skip to content

Instantly share code, notes, and snippets.

@shairontoledo
Last active December 11, 2015 16:08
Show Gist options
  • Save shairontoledo/4625274 to your computer and use it in GitHub Desktop.
Save shairontoledo/4625274 to your computer and use it in GitHub Desktop.
$ ->
contacts = [
{ name: "Contact 1", address: "1, a street, a town, a city, AB12 3CD", tel: "0123456789", email: "anemail@me.com", type: "family" }
{ name: "Contact 2", address: "1, a street, a town, a city, AB12 3CD", tel: "0123456789", email: "anemail@me.com", type: "family" }
{ name: "Contact 3", address: "1, a street, a town, a city, AB12 3CD", tel: "0123456789", email: "anemail@me.com", type: "friend" }
{ name: "Contact 4", address: "1, a street, a town, a city, AB12 3CD", tel: "0123456789", email: "anemail@me.com", type: "colleague" }
{ name: "Contact 5", address: "1, a street, a town, a city, AB12 3CD", tel: "0123456789", email: "anemail@me.com", type: "family" }
{ name: "Contact 6", address: "1, a street, a town, a city, AB12 3CD", tel: "0123456789", email: "anemail@me.com", type: "colleague" }
{ name: "Contact 7", address: "1, a street, a town, a city, AB12 3CD", tel: "0123456789", email: "anemail@me.com", type: "friend" }
{ name: "Contact 8", address: "1, a street, a town, a city, AB12 3CD", tel: "0123456789", email: "anemail@me.com", type: "family" }
]
class Contact extends Backbone.Model
defaults:
photo: "img/placeholder.png"
class Directory extends Backbone.Collection
model: Contact
class ContactView extends Backbone.View
tagName: "article",
className: "contact-container",
template: $("#contactTemplate").html()
render: ->
tmpl = _.template @template
$(@el).html tmpl(@model.toJSON())
this
class DirectoryView extends Backbone.View
el: $("#contacts")
initialize: ->
@collection = new Directory(contacts)
@render()
render: -> @renderContact(item) for item in @collection.models
renderContact: (item) ->
contactView = new ContactView model: item
@$el.append(contactView.render().el)
window.directory = new DirectoryView
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment