Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
271 views
in Technique[技术] by (71.8m points)

typeahead.js - ember-cli typeahead causes errors inside ember.js

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...