這是我自己的預輸入燼組件:
組件
App.XTypeaheadComponent = Ember.Component.extend({
suggestionEngine: null,
data: null,
name: null,
selection: null,
init: function() {
var self = this;
this._super();
this.suggestionEngine = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace(self.name),
queryTokenizer: Bloodhound.tokenizers.whitespace,
local: this.data
});
this.suggestionEngine.initialize();
},
didInsertElement: function() {
this.$('#typeahead').typeahead({
hint: true,
highlight: true,
minLength: 1
}, {
name: 'name',
displayKey: this.name,
source: this.suggestionEngine.ttAdapter()
});
this.$().on('typeahead:selected', function (obj, dat, name) {
this.set('selection', dat);
}.bind(this));
},
willDestroyElement: function() {
this.$('#typeahead').typeahead('destroy');
}
});
組件模板
<script type="text/x-handlebars" data-template-name="components/x-typeahead">
{{input type='text' id='typeahead'}}
</script>
在行動:
http://emberjs.jsbin.com/vetaro/3/edit
沒有造型包括
試圖在一個jsbin。不適合我... – Oliver