Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Twitter bootstrap Typeahed.js不过滤_Twitter Bootstrap_Twitter_Typeahead.js - Fatal编程技术网

Twitter bootstrap Typeahed.js不过滤

Twitter bootstrap Typeahed.js不过滤,twitter-bootstrap,twitter,typeahead.js,Twitter Bootstrap,Twitter,Typeahead.js,我正在使用以下基于示例的代码: 取消对本地的注释效果很好,但是使用远程,列表不会被过滤,我会得到所有项目 这是远程服务器返回的JSON: [{carId:1,optionOne:ASD,optionWO:QEW,全名:欧宝},{carId:2,optionOne:FAS,optionWO:QEW,全名:宝马},{carId:3,optionOne:ADD,optionWO:QEW,全名:奔驰}] 谢谢可能的重复,您需要将JSON数组映射到JavaScript数组。请看我标记为重复的问题。在你的猎

我正在使用以下基于示例的代码:

取消对本地的注释效果很好,但是使用远程,列表不会被过滤,我会得到所有项目

这是远程服务器返回的JSON:

[{carId:1,optionOne:ASD,optionWO:QEW,全名:欧宝},{carId:2,optionOne:FAS,optionWO:QEW,全名:宝马},{carId:3,optionOne:ADD,optionWO:QEW,全名:奔驰}]


谢谢

可能的重复,您需要将JSON数组映射到JavaScript数组。请看我标记为重复的问题。在你的猎犬对象中添加一个过滤器,它将正确映射JSON,这将解决你的问题。嗨,本。我听从了你的建议,但没有用。非常感谢您的输入。当您使用remote时,浏览器调试控制台中是否有任何错误?
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()
});