1

我有两个 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>'
        }
    });
4

0 回答 0