我正在尝试将typeahead附加到我的某个模板中的文本输入中。因为Ember使用的把手,jQuery的文档就绪函数不是typeahead定义的地方。放置“模板就绪”代码的适当位置在哪里?我尝试了一个控制器但没有来自typeahead的响应。我认为模板还没有呈现。
App.PersonController = Ember.ObjectController.extend({
isEditing: false,
init: function(){
this._super();
$('.example-films .typeaheadcx').typeahead([{
name: 'best-picture-winners',
remote: 'http://twitter.github.io/typeahead.js/data/films/queries/%QUERY.json',
prefetch: 'http://twitter.github.io/typeahead.js/data/films/post_1960.json',
template: '<p><strong>{{value}}</strong> – {{year}}</p>',
engine: Ember.Handlebars
}]);
},
actions: {
edit: function() {
this.set('isEditing', true);
},
doneEditing: function() {
this.set('isEditing', false);
}
}
});
答案 0 :(得分:5)
正确的位置是didInsertElement
的{{1}}。
例如:
<强>模板强>
Ember.View
查看强>
<script type="text/x-handlebars" data-template-name="foo">
Hello world
</script>