ember.js - Ember Interpolation in a href tag in handlebars template -


i trying make simple link google maps dynamic address inserted href field. have tried code below plus tons of other messing around no luck. how interpolate dynamic ember string in handlebars href field?

i using ember,rails, , handlebars. know how use bindattr if had entire url stored model have address. putting google url every model seemed unnecessary if call once in view.

<h1>{{name}}</h1>  <div>   <p><a {{bindattr href='http://maps.com/?1=address'}}>{{address}}</a></p>  </div>  <h1>{{name}}</h1> <div>   <p><a href='http://maps.google.com/?q={{address}}'>{{address}}</a></p> </div> 

what used fix it

app.location = ds.model.extend(   name: ds.attr('string', defaultvalue: "")   address:  ds.attr('string', defaultvalue: "")   fulladdress: (->     "http://maps.google.com/?q=#{@get('address')}"   ).property('address') ) 

you this, see demo.

basically create mixin common properties , mix in models. example:

app.basemodel = ember.mixin.create({   base: 'http://maps.google.com/?q=',   fulladdress: function(){     return this.get('base') + this.get('address');   }.property('address') });  app.mymodel = ds.model.extend(app.basemodel, {   name: ds.attr('string'),   address: ds.attr('string') }); 

so later use in templates this:

{{#each model}} <h1>{{name}}</h1>   <div>     <p><a {{bind-attr href='fulladdress'}}>{{address}}</a></p>   </div> {{/each}} 

hope helps.


Comments