javascript - underscore template: lookup a variable by name -


i'm looking way lookup value of variable passed underscore template, using string contains variable name. example, suppose template contains following:

<% _.each(detailfields, function(fieldname) { %>     <% print(getvaluebyname(fieldname)); %> <% } %> 

getvaluebyname() function i'm looking for. according underscore documentation, values passed _.template() put local scope using 'with' statement. if understand correctly, means window[fieldname] or this[fieldname] won't work. eval(fieldname) option, i'd rather avoid using eval().

thanks mu, miss obvious. :) thought backbone.marionette passing in attributes of model. didn't realize passing in whole model well, , conveniently named "model". model.attributes[fieldname] solved issue.


Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -