Reputation: 50800
Does Ember have any template helper "get-value-with-key" I found the below usage, but not sure what it does exactly ?
{{get-value-with-key item optionValuePath}}
Upvotes: 2
Views: 2096
Reputation: 1111
You can use the build-in get helper. See docs here: Ember Docs.
Usage example:
{{get object key}}
Note that the get helper will not be able to work on all JavaScript keys. For example, a key with a '.' will not work with the built-in get helper.
For example, if you have a valid JavaScript object like:
const example = {
'example.pdf': 'pdf_url'
}
// You can access this key normally via
example['example.pdf']
however, this will not work in the get helper
{{get this.example 'example.pdf'}}
One solution is to create a helper that can support the types of keys you need to support. For example, I made a helper that can work on keys with a '.' by including '.' in the key name which are escaped like with ''.
{{get this.example 'example\.pdf'}}
The ember twiddle can be found here: twiddle
Other Helpful Sources:
Upvotes: 0
Reputation: 1408
Let's say you have the following object:
var obj = {
"key1": {
"subkey1": "hello world"
}
}
Using Ember 3.18, to access "hello world" from the template, you can do:
{{get obj 'key1.subkey1'}}
Upvotes: 0
Reputation: 409
There is an Ember Get Helper for HTMLBars. You might have to install the Package "ember-get-helper" if you are on ember < 2.1.
{{get object key}}
Upvotes: 3