aurelia安装typeahead.js的步骤

aurelia安装typeahead.js的步骤,aurelia,typeahead.js,Aurelia,Typeahead.js,今天我一直在奥雷利亚试着让typeahead运行一段时间。到目前为止,我有猎犬做它的事,但到目前为止,我还没有运气 安装步骤 npm 打字脚本文件* typings install dt~jquery --global --save typings install dt~typeahead --global --save *旁注:删除了所有量角器ts文件以避免jquery/量角器$冲突 将这些添加到aurelia.json供应商包 "jquery", { "name" : "typea

今天我一直在奥雷利亚试着让typeahead运行一段时间。到目前为止,我有猎犬做它的事,但到目前为止,我还没有运气

安装步骤

npm

打字脚本文件*

typings install dt~jquery --global --save
typings install dt~typeahead --global --save
*旁注:删除了所有量角器ts文件以避免jquery/量角器$冲突

将这些添加到aurelia.json供应商包

"jquery",
{
   "name" : "typeaheadjs",
   "path" : "../node_modules/typeahead.js/dist",
   "main" : "typeahead.jquery",
   "deps" : ["jquery"],
   "exports": "$"
},          
{
   "name" : "bloodhound",
   "path" : "../node_modules/typeahead.js/dist",
   "main" : "bloodhound"
}
制作一个样本元素

import * as Bloodhound from 'bloodhound';
import * as $ from 'jquery';
import 'typeaheadjs';

export class Autocomplete{


  activate(){
    debugger;

    var engine = this.makeEngine();
    this.runTypeahead( engine );
  }

  runTypeahead( engine : any ) : void{
    $( "#thetypeahead" )
        .typeahead(null,
        {
            name: 'files',
            source: engine,
            limit: 20
        });
  }

  makeEngine() : any {
    var engine = new Bloodhound({
        queryTokenizer: Bloodhound.tokenizers.whitespace,
        datumTokenizer: Bloodhound.tokenizers.whitespace,
        local: [{ id: 1, name: 'dog' }, { id: 2, name: 'pig' }],
        identify: function(obj) { return obj.id; }
    });

    return engine;
  }
}
错误消息是一个运行时错误,因为它没有将typeahead放在jquery上

Message: $(...).typeahead is not a function

如何加载typeahead插件?

这不是对您问题的回答,但这里有一个零依赖性的Aurelia autocomplete:@JeremyDany我会处理这个问题,让问题保持原样。这方面运气好吗?遇到同样的问题我用了jeremydanyow的那个。我不得不添加样式和一个功能,但它符合我的目的,它非常可修改,易于使用,有点像学习曲线。基本示例使用
webpack
(但是如果没有
bloodhound
,就因为太晚了,明天又是新的一天)。您收到的错误与我在
webpack
datepicker
中收到的消息类似,这个stackoverflow帮助了我。我遇到的问题与
datepicker
尝试加载自己的
jquery
版本有关,这导致了一个问题。另外,请确保
jquery
位于捆绑包的开头,您可以尝试在
prepend
部分中加载
jquery
,和/或可能准备好
Message: $(...).typeahead is not a function