Created
February 5, 2013 17:36
-
-
Save victor-github/4716110 to your computer and use it in GitHub Desktop.
an example of handlebars helper for iteration
This file contains hidden or 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 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 | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
used with Ember.js