typeahead + BloodHound建议引擎不显示Json和

时间:2017-06-14 15:20:27

标签: jquery angularjs json typeahead bloodhound

所以,我正在使用bloodhound建议引擎和typeahead用于searchBar / suggestionBar,它应该从 JSON 中显示“providerName”(此信息来自某些文本输入) strong> PHP mongo服务器。 这里的一个大问题是,我认为它不喜欢我上传的json,因为我已经尝试过像这样的其他jsons http://revox.io/json/countries-list.json 它工作正常。但是我的不是。 这里的特点是,当我在搜索栏中按“o”时,它会显示json文件本身(不是讨论它的信息,而是JSON FILE本身)。 最后,我只想让搜索栏显示“providerName”,其余部分对此部分并不重要

** js脚本我用来从php服务器调用JSON(它的工作原理  国家JSON很好)**

var providers = new Bloodhound({
        datumTokenizer: Bloodhound.tokenizers.obj.whitespace('providerName'),
        queryTokenizer: Bloodhound.tokenizers.whitespace,
        prefetch: 'http://localhost:63342/insurancev2/api/apps/inventory/requestProviders.php'
    });
    // initialize the bloodhound suggestion engine
    $scope.countriesOptions = {
        highlight: true
    };
    $scope.providerData = {
        name: 'providersName',
        source: providers
    }
    $scope.provider = null;




}])

我上传的JSON

{ "593f280575938b4e020041ff": { "_id": { "$id": "593f280575938b4e020041ff" }, "providerName": "jose", "providerPhone": "898799", "providerEmail": "ajfjafjj", "providerContact": "enriquie", "providerBank": "980988098" }, "59400bfe75938b4a0200420e": { "_id": { "$id": "59400bfe75938b4a0200420e" }, "providerName": "Cafe Duran", "providerPhone": "888-908", "providerEmail": "durancafe@outlook.com", "providerContact": "KC", "providerBank": "89876798" }, "59413d7c75938bea0a00428e": { "_id": { "$id": "59413d7c75938bea0a00428e" }, "providerName": "cafecito", "providerPhone": "1-581-88", "providerEmail": "jppiipi", "providerContact": "jose", "providerBank": "78909876" }, "59413fff75938bea0a0042a1": { "_id": { "$id": "59413fff75938bea0a0042a1" }, "providerName": "josesillo", "providerPhone": "41515", "providerEmail": "josesgf", "providerContact": "999899", "providerBank": "-98888" }, "594140bf75938bea0a0042a8": { "_id": { "$id": "594140bf75938bea0a0042a8" }, "providerName": "114", "providerPhone": "44141", "providerEmail": "41414", "providerContact": "11414", "providerBank": "1414" }, "594140f575938bea0a0042af": { "_id": { "$id": "594140f575938bea0a0042af" }, "providerName": "a13r41", "providerPhone": "1414", "providerEmail": "1414", "providerContact": "1414", "providerBank": "4141" }, "5941444175938bea0a0042c8": { "_id": { "$id": "5941444175938bea0a0042c8" }, "0": "calcuta", "1": "8987899", "2": "calcuta@outlook.cokj", "3": "casaornage", "4": "9876546789" }, "5941458975938bea0a0042e7": { "_id": { "$id": "5941458975938bea0a0042e7" }, "providerName": "saquela", "providerPhone": "cagafe", "providerEmail": "jose", "providerContact": "fqf", "providerBank": "qsfqw" } }

1 个答案:

答案 0 :(得分:0)

考虑像下面这样添加display选项。并提供name是可选的。

$scope.providerData = {
    display: 'providersName',
    source: providers
}