0

Using Typeahead-Bloodhound bundle, I've created a custom suggestion template. I'm trying to figure out what object the template is calling to compile a variable. I'm using Underscore instead of the {{}} templating:

_.compile( '<p><strong><%=PN%></strong> <span class="tt-suggestion-etc"> <%=A2 %>| LAT: <%=Y%> LON: <%=X%></span></p>' )

If this were the standard Typeahead brackets:

compile( '<p><strong>{{PN}}</strong> <span class="tt-suggestion-etc"> {{A2}}| LAT: {{Y}} LON: {{X}}</span></p>' )

I want to be able to access the actual object property via javascript in Underscore, like so:

_.compile( '<p><strong><%=PN%></strong> <span class="tt-suggestion-etc"> <% if(someObj.someProp !== undefined ){ // do something }else{ //do something else } %>| LAT: <%=Y%> LON: <%=X%></span></p>')

MaxRocket
  • 920
  • 1
  • 12
  • 26

1 Answers1

0

After playing with console.log(this) in the template, I dug deep enough to find that the answer is "obj". As in obj.thisProp, obj.thatProp. So now I can do this:

_.compile( '<p><strong><%=PN%></strong> <span class="tt-suggestion-etc"> <% if(obj.someProp !== undefined ){ // do something }else{ //do something else } %>| LAT: <%=Y%> LON: <%=X%></span></p>')

Hope this helps someone else looking for the answer!

MaxRocket
  • 920
  • 1
  • 12
  • 26