Reputation: 38583
I am using a third party library typeaheadjs for an ajax drop down.
I want to render an ember view in each dropdown element, typeahead supports a suggestion hook for this. I need it to be a propper Ember.Handlebars
binding because sometimes my ember-data models displayKey will require multiple requests to the server as all my model relationships are { async : true }
suggestion: function(model){ //this hook is part of the typeahead api
var view = Ember.View.create({
model : model,
template: Ember.Handlebars.compile('Hello {{model.id}}')
}).createElement();
return view.element; //need to return the html tag to render within each <li>
},
model
is an ember-data model. The return element needs to be the html to insert into each <li>
tag. The following works but the binding {{model.id}}
is never rendered, I just get Hello
.
Any ideas why? I guess I am not running a function that will kick off the bindings or something.
Upvotes: 1
Views: 46
Reputation: 106
The default context of the compiled template is the view's controller. So replace model : model
with controller : model
.
Also you can access view's properties from template in following way:
'Hello {{view.model.id}}'
Upvotes: 2