typeahead.js: Uncaught TypeError: Cannot read property 'length' of null
typeahead.js: Uncaught TypeError: Cannot read property 'length' of null
我查看了所有其他 'length' of null
个问题,但它们对我没有帮助。
我正在学习 YouTube 教程以使用 typeahead.js 将自动建议实现到表单中,但它不起作用。 Chromes 控制台输出:
Uncaught TypeError: Cannot read property 'length' of null
谁能帮我指出我哪里错了。
这里是相关的html:
<form action="index.php" method="get" autocomplete="off">
<input type="text" name="user" id="users">
<input type="submit" value="Go">
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="js/typeahead.js"></script>
<script src="js/global.js"></script>
和相关的js:
$(document).ready(function() {
var users = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('username'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: 'users.php?query=%QUERY'
});
users.initialize();
$('#users').typeahead({
hint: true,
highlight: true,
//minLength: 2
}, {
name: 'users',
displayKey: 'username',
source: users.ttAdapter() // what is ttAdapter() ?
});
});
在 YouTube 教程评论中,有人指出了这一点:
Worked for me when i replaced:
remote: 'users.php?query=%QUERY'
with:
remote: {
url: 'users.php?query=%QUERY',
wildcard: '%QUERY'
}
现在可以了。
我查看了所有其他 'length' of null
个问题,但它们对我没有帮助。
我正在学习 YouTube 教程以使用 typeahead.js 将自动建议实现到表单中,但它不起作用。 Chromes 控制台输出:
Uncaught TypeError: Cannot read property 'length' of null
谁能帮我指出我哪里错了。
这里是相关的html:
<form action="index.php" method="get" autocomplete="off">
<input type="text" name="user" id="users">
<input type="submit" value="Go">
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="js/typeahead.js"></script>
<script src="js/global.js"></script>
和相关的js:
$(document).ready(function() {
var users = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('username'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: 'users.php?query=%QUERY'
});
users.initialize();
$('#users').typeahead({
hint: true,
highlight: true,
//minLength: 2
}, {
name: 'users',
displayKey: 'username',
source: users.ttAdapter() // what is ttAdapter() ?
});
});
在 YouTube 教程评论中,有人指出了这一点:
Worked for me when i replaced:
remote: 'users.php?query=%QUERY'
with:
remote: {
url: 'users.php?query=%QUERY',
wildcard: '%QUERY'
}
现在可以了。