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
Post a Comment