Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds an "$index" property (similar to the each tag) to the data item …
…passed to nested templates using the {{tmpl}} tag fixes: https://github.com/jquery/jquery-tmpl/issues#issue/28
- Loading branch information
993e6fa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! this snippet helped me get my nested templates with jQuery UI tabs working, since they need the index in the div id. You the man.
993e6fa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! The lack of $index was one of my chief frustrations with this library! Especially after the MS AJAX Library (that got scrubbed for this turd) was so comparatively robust.
993e6fa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that is a good improvement but could be better if you don't modify the original dataItem. Think about modify the newTmplItem:
return dataItem ? newTmplItem( options, parentItem, tmpl, dataItem, index ) : null;
If you print your datasource after the template render, all items includes the $index attribute, and this modification provoke an error in other places in my application.