Skip to content

Instantly share code, notes, and snippets.

@victor-github
Created February 5, 2013 17:36
Show Gist options
  • Save victor-github/4716110 to your computer and use it in GitHub Desktop.
Save victor-github/4716110 to your computer and use it in GitHub Desktop.
an example of handlebars helper for iteration
<table class="table table-bordered">
{{#each_in_group this}}
{{view App.ShowNoteView noteBinding="this"}}
{{/each_in_group}}
</table>
//a helper for iteration
Handlebars.registerHelper('each_in_group', function(context, options) {
var date = options.contexts[0], //the argument
group = App.notesController.get('dates_notes')[date],
fn = options.fn,
buffer = "<div class='notes_list_group_date'>" + date + "</div>";
for (var i = 0, j = group.length; i < j; i++) {
var item = group[i];
buffer += fn(item); //item is what "this" becomes when our code is being evaluated; fn is result of executing our code
}
return buffer
});
@victor-github
Copy link
Author

used with Ember.js

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