【发布时间】:2016-05-04 09:48:11
【问题描述】:
我有以下功能,我想每次都被调用,用户在typeahead输入字段中输入一些内容。
function getAllActiveUsers() {
var userList = $('#usersTable').jqGrid('getGridParam').userData;
var userNames = {};
if(userList) {
// Return the list of all active users
$(userList).each(function() {
if(this.userStatus != 1) {
// If the user is verified
// Could be active/inactive
userNames.user = this.username;
}
});
}
return JSON.stringify(userNames);
}
HTML:
<div id="the-basics">
<input class="typeahead" type="text" data-provide="typeahead" placeholder="User List">
</div>
我一直在浏览examples,但不明白如何实现此功能。
编辑:
为什么当我初始化为时它不起作用:
$('.typeahead').typeahead({
source : getAllActiveUsers
});
【问题讨论】:
-
调用
$('.typeahead').on('keyup',getAllActiveUsers())上的函数试试这个 -
您使用的是哪种类型的预输入?您指的是 typehead.js,但有些东西告诉我您使用的是不同的?
-
getAllActiveUsers返回什么?
标签: javascript jquery typeahead.js typeahead bootstrap-typeahead