Skip to content

Instantly share code, notes, and snippets.

@mxriverlynn
Created February 22, 2012 02:02
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mxriverlynn/1880628 to your computer and use it in GitHub Desktop.
Save mxriverlynn/1880628 to your computer and use it in GitHub Desktop.
ember: clicking html elements
EmberCloneMail.EmailListView = Em.View.extend({
tagName: "ul",
classNames: ["email-list", "email-view"],
templateName: "email-list-view"
});
EmberCloneMail.EmailPreview = Em.View.extend({
tagName: "li"
templateName: "email-preview"
});
<script data-template-name="email-list-view" type="text/x-handlebars">
{{#each EmberCloneMail.emailListController}}
{{view EmberCloneMail.EmailPreview contentBinding="this"}}
{{/each}}
</script>
<script data-template-name="email-preview" type="text/x-handlebars">
{{#with content}}
<span class="from">{{from}}</span>
<span class="subject">{{subject}}</span>
<span class="date">{{date}}</span>
{{/with}}
</script>
EmberCloneMail.EmailPreview = Em.View.extend({
tagName: "li"
templateName: "email-preview",
click: function(e){
// handle the view click here
}
});
<script data-template-name="email-preview" type="text/x-handlebars">
{{#with content}}
<span class="from" {{action "doStuff" on="click"}}>{{from}}</span>
<span class="subject">{{subject}}</span>
<span class="date">{{date}}</span>
{{/with}}
</script>
EmberCloneMail.EmailPreview = Em.View.extend({
tagName: "li"
templateName: "email-preview",
doStuff: function(){
// do stuff here, based on the click of the HTML element
}
});
EmberCloneMail.EmailPreview = Em.View.extend(Ember.TargetActionSupport, {
// tag, template, etc here
});
<script data-template-name="email-list-view" type="text/x-handlebars">
{{#each EmberCloneMail.emailListController}}
{{view EmberCloneMail.EmailPreview contentBinding="this"
target="EmberCloneMail.emailController"
action="showEmail"
}}
{{/each}}
</script>
<script data-template-name="email-preview" type="text/x-handlebars">
{{#with content}}
<span class="from">{{from}}</span>
<span class="subject">{{subject}}</span>
<span class="date">{{date}}</span>
{{/with}}
</script>
EmberCloneMail.EmailPreview = Em.View.extend(Ember.TargetActionSupport, {
// tag, template, etc her
click: function(e){
// call the targeted controller / action
this.triggerAction();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment