Typeahead.js没有过滤

时间:2014-11-19 15:04:21

标签: twitter-bootstrap twitter typeahead.js

我使用以下代码,我基于示例https://twitter.github.io/typeahead.js/examples/

var carArray = [{ carId: 1, fullName: 'Opel' }, { carId: 2, fullName: 'BMW' }, { carId: 3, fullName: 'Mercedes' }];
var cars = new Bloodhound({
    datumTokenizer: Bloodhound.tokenizers.obj.whitespace('fullName'),
    queryTokenizer: Bloodhound.tokenizers.whitespace,
    //local: carArray,
    remote: '/api/cars'
});

cars.initialize();

$(elt).typeahead(null, {
    name: 'car',
    displayKey: 'fullName',
    source: cars.ttAdapter()
});

取消注释local它可以正常工作,但是remote列表不会被过滤,我会收到所有项目。

所以这是remote

返回的JSON

[{"carId":1,"optionOne":"ASD","optionTwo":"QEW","fullName":"Opel"}, {"carId":2,"optionOne":"FAS","optionTwo":"QEW","fullName":"BMW"},{"carId":3,"optionOne":"ADD","optionTwo":"QEW","fullName":"Mercedes"}]

谢谢

0 个答案:

没有答案