Handlebars has a built-in helper called lookup
. The documentation is not very clear about how it works. Could I see an example?
标签:
handlebars.js
相关问题
- ember component based on model type
- Ember yield param passing
- Access attributes of the DOM elements from ember.j
- Minify HTML files in text/html templates
- Handlebars Block Helper : each with sort
相关文章
- How to use autofocus with ember.js templates?
- How to integrate Handlebars template to Marionette
- How to pass Express response object to frontend JS
- JQuery, Ajax, Handlebars clear table then repopula
- Registering handlebars helpers with node does abso
- set the first radio button is checked in handlebar
- Error: Missing Helper in Handlebars.js
- Handlebars.js - Access object value with a variabl
The lookup property is useful if we don't know the name of the property we want, for instance because it's in a variable or the result of an expression.
If we have this object:
We could put this in the HTML like this:
Which is equivalent to:
Maybe we don't know that we want the title. Say the property name is somewhere in a variable instead:
Now we could show the book title like this:
Sure, past me! Here's an example from your future.
Suppose you have an object or array
arr
and a variablekey
and you want to output the value ofarr[key]
, you would use the lookup helper{{lookup arr key}}
.The code defining the helper is simply: