无法读取null的属性'length'(typeahead)

时间:2016-07-21 07:38:05

标签: javascript jquery typeahead.js bloodhound

我对Twitter Typeahead有点麻烦。它抛出了以下错误:

Uncaught TypeError: Cannot read property 'length' of null jquery.js:4

我看了一些其他案例,但没有一个与我相符。

我的代码:

    var companies = new Bloodhound({
        datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
        queryTokenizer: Bloodhound.tokenizers.whitespace,
        remote: {
            url: '_companies?query=%QUERY',
            wildcard: '%QUERY'
        }
    });

    var users = new Bloodhound({
        datumTokenizer: Bloodhound.tokenizers.obj.whitespace('username'),
        queryTokenizer: Bloodhound.tokenizers.whitespace,
        remote: {
            url: '_users?query=%QUERY',
            wildcard: '%QUERY'
        }
    });

    companies.initialize();
    users.initialize();

    $('#username').typeahead({
        hint: true,
        highlight: true,
        minLength: 1
    }, {
        name: 'companies',
        displayKey: 'name',
        source: companies.ttAdapter(),
        templates: {
            header: '<h4 class="hint-title">Bedrijven</h4>'
        }
    }, {
        name: 'users',
        displayKey: 'username',
        source: users.ttAdapter(),
        templates: {
            header: '<h4 class="hint-title">Gebruikers</h4>'
        }
    });

也许有其他人有类似的问题?

0 个答案:

没有答案