我正在尝试附加一个预先输入 https://github.com/twitter/typeahead.js/到我的模板之一中的文本输入。因为 Ember 使用把手,所以 jQuery 的文档就绪函数不是用于预输入定义的地方。放置“模板就绪”代码的正确位置在哪里?我尝试了一个控制器,但预输入没有任何响应。我认为模板尚未呈现。
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);
}
}
});
正确的地方是didInsertElement
of Ember.View
.
例如:
Template
<script type="text/x-handlebars" data-template-name="foo">
Hello world
</script>
View
App.FooView = Ember.View.extend({
templateName: 'foo',
didInsertElement: function() {
console.log(this.$().text()); // will log 'hello world'
}
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)