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.

ember twiddle


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -