javascriptember.jshandlebars.jsember-components

return an object value from ember helper and passing through hbs template


can ember return an object value from helper, and if that can how to passing to hbs template for component. Exactly I just wanna do this.

import Ember from 'ember';

export function someHelper(params/*, hash*/) {
  switch(params) {
    case 'a':
     return { a:21,b:22 }
     break;
    case 'b':
     return { a:21,b:20 }
     break;
    default:
     return { a:2,b:211 } 
  }
}):

And this is a hbs template

<p>{{some-helper object.foo}} </p>

how to get the value from ember helper that return object to my hbs template??


Solution

  • You can use the get helper provided by Ember; see the api reference. I modified your helper and used get helper in the following twiddle to illustrate you the usage. By the way, params passed to helper is an array so I got the first item (0 index) from the array for the switch case you have provided. See application.hbs to see get helper in action. My best regards.