0

我已经对此进行了几个小时的故障排除,但无济于事。

基本上,在下面的代码中,我从远程建议提供者那里得到了正确的结果,

            var descuentos = new Bloodhound({
            datumTokenizer: Bloodhound.tokenizers.nonword,
            queryTokenizer: Bloodhound.tokenizers.nonword,
            remote: {
                url: 'http://localhost:30045/Home/Suggest?q=%QUERY&type=name&fuzzy=false',
                wildcard: "%QUERY",
                filter: function (items) {
                    return $.map(items, function (item) {
                        return {
                            value: item.NombreComercio
                        };
                    });
                }
            }
        });

        $('#bloodhound .typeahead').typeahead({
            hint: true,
            highlight: true,
            minLength: 0
        },
        {
            name: 'descuentos',
            source: descuentos
        });

<body>
    <div id="bloodhound">
        <input class="typeahead" type="text" placeholder="Comercio Adherido...">
    </div>
</body>

但是,当建议以搜索字符串开头时,不会显示...想法?

谢谢!

4

1 回答 1

0

添加displayKey到预先输入的数据集参数。

$('#bloodhound .typeahead').typeahead({
  hint: true,
  highlight: true,
  minLength: 0
},{
  name: 'descuentos',
  displayKey: 'value',
  source: descuentos
});

希望这可以帮助。

于 2015-04-30T01:18:34.120 回答