Created
June 6, 2012 01:00
-
-
Save superchris/2879204 to your computer and use it in GitHub Desktop.
composite views blog pot code
This file contains 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
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"] @ |
This file contains 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
class Example.Views.TableRowView extends Backbone.View | |
render: -> | |
@$el.html JST["table_row_view_template"] @ |
This file contains 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
%tr | |
%td= @model.get("first_name") | |
%td= @model.get("last_name") |
This file contains 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
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"] @ |
This file contains 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
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() |
This file contains 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
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>" |
This file contains 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
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() | |
This file contains 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
%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