ember-cli typeahead causes errors inside ember.js

放肆的年华 提交于 2020-01-07 07:09:13

问题


installed type-ahead component from bower.

and try to use

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

component in action. it causes errors inside ember.js (_changeSingle and afterFunc functions)

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

Uncaught TypeError: Cannot read property 'nextSibling' of null

is it for versions?


回答1:


Here is my own typeahead ember component:

Component

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');
  }
});

Components Template

<script type="text/x-handlebars" data-template-name="components/x-typeahead">
  {{input type='text' id='typeahead'}}
</script>

In Action:

http://emberjs.jsbin.com/vetaro/3/edit

No styling included



来源:https://stackoverflow.com/questions/24824578/ember-cli-typeahead-causes-errors-inside-ember-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!