我今天一直试图让Aurelia先前跑步。到目前为止,我已经得到了猎犬来做这件事,但到目前为止还没有运气好吗?
安装步骤
NPM
npm install jquery --save
npm install typeahead-js --save
npm install typeahead.js-bootstrap4-css --save
打字稿文件*
typings install dt~jquery --global --save
typings install dt~typeahead --global --save
*旁注:删除所有量角器ts文件以回避jquery / protractor $冲突。
将这些添加到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
如何获取要加载的预先输入插件?