0

從bower中安裝的輸入類型組件。ember-cli typeahead會在ember.js中導致錯誤

,並嘗試在行動中使用

{{type-ahead data=companies name="name" selection=selectedCompany}}

組件。它會導致內ember.js錯誤(_changeSingle和afterFunc功能)

"Uncaught TypeError: Cannot read property 'selectedIndex' of undefined " 

Uncaught TypeError: Cannot read property 'nextSibling' of null

是它的版本?

+0

試圖在一個jsbin。不適合我... – Oliver

回答

1

這是我自己的預輸入燼組件:

組件

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

沒有造型包括