javascript - underscore.js templating, iterating over "this" -


how iterate on "this" (or data object passed template) using underscore.js templating? example, if pass data object template:

obj = {name: "ben", description: "funny looking"}  var template = _.template("<ul> <% _.each(this, function(x, y){ print('<li>'+x+'<li>')}) %> </ul>");   var compiled = template(obj);  

i expect "this" in iterator loop on data object (like in handlebars), it's not working. ordinarily i'd directly enter <%= name %> template, in case, object keys being determined dynamically.

any ideas on how this? thanks!

here's easy solution:

var compiled = template({data:obj});  

and iterate on "data"


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -