简体   繁体   中英

Writing a handlebars helper in Ember

In my app I am trying to write a custom handlebars helper. My helper looks like this

Ember.Handlebars.helper('__', function(person) {
   console.log(person);
   return person.get('name');
}, 'name');

I have a person class like this

App.Person = Ember.Object.extend({
  name : 'moshin'
});

In my hbs file I am trying and doing this

{{__ person}}

But it outputs undefined. Can anybody explains how to go about it?

Is person actually defined in your template? Your logic there is spot on. I'm guessing maybe you've failed to create an instance of person, and maybe you aren't referencing it in the template correctly. Here's an example of your code, working...

http://emberjs.jsbin.com/fuwahemi/1/edit

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM