Skip to content

Instantly share code, notes, and snippets.

@superchris
Created June 6, 2012 01:00
Show Gist options
  • Save superchris/2879204 to your computer and use it in GitHub Desktop.
Save superchris/2879204 to your computer and use it in GitHub Desktop.
composite views blog pot code
class Example.Views.TableRowView extends Backbone.View
tagName: "tr"
attributes: ->
id: "row_#{@model.id}"
constructor: (options) ->
super
@parentView = options.parentView
@parentView.on "rendered", =>
@setElement @parentView.$("#row_#{@model.id}")
@render()
toHtml: ->
@$el.clone().wrap("<p>").parent().html()
events:
"click td": "clicked"
clicked: ->
alert "Way to go, you clicked a cell!"
render: ->
@$el.html JST["table_row_view_template"] @
class Example.Views.TableRowView extends Backbone.View
render: ->
@$el.html JST["table_row_view_template"] @
%tr
%td= @model.get("first_name")
%td= @model.get("last_name")
class Example.Views.TableRowView extends Backbone.View
events:
"click td": "clicked"
clicked: ->
alert "Way to go, you clicked a cell!"
render: ->
@$el.html JST["table_row_view_template"] @
class Example.Views.TableView extends Backbone.View
render: ->
@$el.html JST["table_view_template"] @
tableRow: (person) ->
tableRowView = new Example.Views.TableRowView(model: person)
tableRowView.render()
tableRowView.$el.html()
class Example.Views.TableView extends Backbone.View
render: ->
@$el.html JST["table_view_template"] @
for person in @collection.models
tableRowView = new Example.Views.TableRowView(model: person, el: @$("#row_#{person.id}"))
tableRowView.render()
tableRow: (person) ->
"<tr id='row_#{person.id}'></tr>"
class Example.Views.TableView extends Backbone.View
render: ->
@$el.html JST["table_view_template"] @
@trigger "rendered"
tableRow: (person) ->
new Example.Views.TableRowView(parentView: @, model: person).toHtml()
%table.table-bordered
%thead
%tr
%th First Name
%th Last Name
%tbody
- for person in @collection.models
= @tableRow(person)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment