Skip to content

Instantly share code, notes, and snippets.

@jayhjkwon
Created March 25, 2013 10:36
Show Gist options
  • Save jayhjkwon/5236270 to your computer and use it in GitHub Desktop.
Save jayhjkwon/5236270 to your computer and use it in GitHub Desktop.
Backbone View with CoffeeScript
class AboutModel extends Backbone.Model
defaults:
firstName: 'Hyojung'
class HomeView extends Backbone.View
initialize: ->
@render()
render: ->
templateContent = $('#home-template').html()
template = _.template templateContent
@$el.html(template)
@
events:
'click #btn-hello': 'onClick'
onClick: =>
alert 'Hello'
class AboutView extends Backbone.Marionette.ItemView
initialize: ->
@listenTo @model, 'change:firstName', @onUpdate if @model
@render()
render: ->
templateContent = $('#about-template').html()
template = _.template templateContent
if @model
compiled = template @model.toJSON()
else
compiled = template
@$el.html compiled
@
events:
'keyup #txt-hello': 'onKeyUp'
onKeyUp: (event) =>
@model.set firstName: $('#txt-hello').val()
onUpdate: ->
$('#span-hello').text @model.get 'firstName'
move : ->
console.log 'hello coffee script'
class MyView extends AboutView
@jayhjkwon
Copy link
Author

test

@jayhjkwon
Copy link
Author

test

@jayhjkwon
Copy link
Author

testtest

@jayhjkwon
Copy link
Author

test

@jayhjkwon
Copy link
Author

111

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment