emberjs应该记录准备好的功能吗?

时间:2013-10-27 14:45:34

标签: ember.js handlebars.js

我正在尝试将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);
        }
    }
});

1 个答案:

答案 0 :(得分:5)

正确的位置是didInsertElement的{​​{1}}。

例如:

<强>模板

Ember.View

查看

<script type="text/x-handlebars" data-template-name="foo">
  Hello world
</script>