Emmanuel P.
Emmanuel P.

Reputation: 1006

Ember Object Property definition

Here's my question:

I have a list of books, with the isAvailable boolean property

I would like to create a property called availability, which will return "product available" if isAvailable, and I'd like to use this property in an #eachstatement

availability: function () {
    if (this.get('isAvailable'))
        return "book available";
    else
        return "book not available";
    }.property()


{{#each book in arrangedContent}}
    {{availability}}
{{/each}}

In which object must I define my new property?

Upvotes: 0

Views: 35

Answers (1)

enspandi
enspandi

Reputation: 663

Extend your books model:

var model;

model = DS.Model.extend({
  isAvailable: DS.attr('boolean'), // This is what you already have

  availability: function() {
    if (this.get('isAvailable')) {
      return 'book available';
    } else {
      return 'book not available';
    }
  }.property('isAvailable')


});

export default model;

In your template you have to write book.availability...

Upvotes: 1

Related Questions