Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember.js bindAttr plus plaintext

How can I bind an attribute and concatenate some plaintext with it?

For example:

<span {{bindAttr title="updates 'revisions'"}}>{{updates}} revisions</span>

To produce:

<span title="4 revisions">4 revisions</span>

Is there a way to do this without writing a new helper? I feel like I have to write a helper for every simple thing with Handlebars...

like image 863
EsTeGe Avatar asked Oct 21 '22 04:10

EsTeGe


1 Answers

You can add to you model new calculated field

App.Revisions = Em.Object.extend({
   updates:5,
   updatesTitle:function(){
     return this.get('updates') + ' revisions';
   }.property('updates'),
});

In Handlebars change to:

<span {{bindAttr title="updatesTitle"}}>{{updates}} revisions</span>

or

<span {{bindAttr title="updatesTitle"}}>{{updatesTitle}}</span>
like image 189
St_5 Avatar answered Oct 25 '22 19:10

St_5