Templates.helpers.get()

getpublic

Defined in packages/ember-htmlbars/lib/keywords/get.js:105
Available since 2.1.0

Dynamically look up a property on an object. The second argument to {{get}} should have a string value, although it can be bound.

For example, these two usages are equivilent:

{{person.height}}
{{get person "height"}}

If there were several facts about a person, the {{get}} helper can dynamically pick one:

{{get person factName}}

For a more complex example, this template would allow the user to switch between showing the user's height and weight with a click:

{{get person factName}}
<button {{action (mut factName) "height"}}>Show height</button>
<button {{action (mut factName) "weight"}}>Show weight</button>

The {{get}} helper can also respect mutable values itself. For example:

{{input value=(mut (get person factName)) type="text"}}
<button {{action (mut factName) "height"}}>Show height</button>
<button {{action (mut factName) "weight"}}>Show weight</button>

Would allow the user to swap what fact is being displayed, and also edit that fact via a two-way mutable binding.

doc_EmberJs
2016-11-30 16:53:33
Comments
Leave a Comment

Please login to continue.