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

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -