ember-cli typeahead会在ember.js中导致错误

时间:2014-07-18 12:03:12

标签: ember.js typeahead.js bootstrap-typeahead typeahead ember-cli

从凉亭安装预先输入组件。

并尝试使用

  

{{提前数据=公司名称="名称"选择= selectedCompany}}

组件在行动中。它会导致ember.js(_changeSingle和afterFunc函数)中的错误

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

未捕获的TypeError:无法读取属性' nextSibling'为null

适用于版本吗?

1 个答案:

答案 0 :(得分: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

不包含样式