Skip to content

Instantly share code, notes, and snippets.

@martsie
Created January 25, 2017 08:38
Show Gist options
  • Save martsie/bfe40af7a9dbc81b7224501be1938deb to your computer and use it in GitHub Desktop.
Save martsie/bfe40af7a9dbc81b7224501be1938deb to your computer and use it in GitHub Desktop.
Backbone model and collection implementation with external resource in CoffeeScript
# Define the model.
class Comment extends Backbone.Model
defaults:
name: 'test'
email: '[email protected]'
body: 'BODY'
# Define the collection.
class CommentCollection extends Backbone.Collection
model: Comment
url: 'http://jsonplaceholder.typicode.com/comments'
# Create a new instance of the collection.
comments = new CommentCollection
# Fetch comments from the API url.
comments.fetch
success: ->
models = comments.models
console.log models
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment