用于多个数据集的Typeahead / Bloodhound dupDetector

时间:2015-03-19 06:30:37

标签: autocomplete typeahead bloodhound

我有两个Bloodhound数据集,一个本地数据集和一个远程数据集。本地数据将始终在远程结果中重复。我找到了Typeahead文档中提到的dupDetector方法,但似乎只有当我的本地和远程数据集都在同一个Bloodhound对象中构建时,此方法才有效。

这是我的代码。有没有办法在多个Bloodhound数据集中过滤重复项?

    var local_props = new Bloodhound({
        datumTokenizer: function (p) {
            return Bloodhound.tokenizers.whitespace(p.name);
        },
        queryTokenizer: Bloodhound.tokenizers.whitespace,
        local: portfolio_props,
        limit: 100
    });

    var remote_props = new Bloodhound({
        datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
        queryTokenizer: Bloodhound.tokenizers.whitespace,
        remote: 'properties/searchPropertiesLike?substr=%QUERY',
        dupDetector: function(remoteMatch, localMatch) {
            return remoteMatch.name === localMatch.name;
        },
        limit: 100
    });

    local_props.initialize();
    remote_props.initialize();

    $('#typeahead-property').typeahead({
        hint: true,
        highlight: true,
        minLength: 2
    },
    {
        name: 'port_properties',
        displayKey: 'name',
        source: local_props.ttAdapter(),
        templates: {
            header: '<h3>Your Portfolio Properties</h3>'
        }
    },
    {
        name: 'dir_properties',
        displayKey: 'name',
        source: remote_props.ttAdapter(),
        templates: {
            header: '<h3>Properties Directory</h3>'
        }
    });

0 个答案:

没有答案