Skip to content

Instantly share code, notes, and snippets.

@dpritchett
Created July 19, 2011 18:22
Show Gist options
  • Save dpritchett/1093329 to your computer and use it in GitHub Desktop.
Save dpritchett/1093329 to your computer and use it in GitHub Desktop.
jQuery ($) ->
window.Plant = Backbone.Model.extend
testFun: (name) ->
return "Hello, #{name}"
vitals: ->
return @get 'vitals'
window.PlantView = Backbone.View.extend
tag : 'li'
className : 'plant'
initialize: ->
#_.bindAll(this, 'render')
@model.bind('change', @render)
@template = _.template($('#plant-template').html())
render: =>
renderedContent = @template(@model.toJSON())
$(@el).html(renderedContent)
return this
console.log "Loaded!"
"""
When I try to append a plant view to my page i get an error:
plant = new window.Plant({name: 'Carrot', values: [1,2,3,4]})
inherits.child
plantView = new window.PlantView({model:plant})
inherits.child
$('#container').append(plantView.render().el)
TypeError: Cannot call method 'toJSON' of undefined
"""
jQuery ($) ->
window.Plant = Backbone.Model.extend
testFun: (name) ->
return "Hello, #{name}"
vitals: ->
return @get 'vitals'
window.PlantView = Backbone.View.extend
tag : 'li'
className : 'plant'
initialize: ->
_.bindAll(this, 'render')
@model.bind('change', @render)
@template = _.template($('#plant-template').html())
render: ->
renderedContent = @template(@model.toJSON())
$(@el).html(renderedContent)
return this
console.log "Loaded!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment