ember.js - Get helper in hbs when getting nested object -
suppose have following objects:
image: { size: { l: { url: 'l.jpg', }, m: { url: 'm.jpg', }, s; { url: 's.jpg', } } }, mysize: 'm'
if want corresponding image url in template, how should that? tried:
{{get image mysize 'url'}}
but not work.
i can url want typing this:
{{get (get image mysize) 'url')}}
however unintuitive , ugly workaround. there better way? thank you.
you need use concat helper along it:
{{get image (concat 'size.' mysize '.url')}}
but sounds job computed property:
imageurl: ember.computed('mysize', 'image.size', function() { let { image, mysize } = this.getproperties('image', 'mysize'); return ember.get(image, `size.${mysize}.url`); })
that way can use {{imageurl}}
in template.
Comments
Post a Comment