Created
January 25, 2017 08:38
-
-
Save martsie/bfe40af7a9dbc81b7224501be1938deb to your computer and use it in GitHub Desktop.
Backbone model and collection implementation with external resource in CoffeeScript
This file contains hidden or 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
# 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