- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想利用 ui.bootstrap.typeahead,因为它非常棒。我正在执行一个可能包含数百万用户的数据库搜索,所以我真的很希望能够在调用 $http 之前消除搜索框中的击键。否则,每次击键都会导致搜索,而较早的击键产生的搜索速度会比后来的击键慢,从而导致笨拙的用户体验。
我目前的努力,这是行不通的,看起来是这样的:
JavaScript:
angular.module("mycontrollers").controller("myCtrl", [
"$scope", "$http", "rx", "localisationService", "close", function ($scope, $http, rx, localisationService, close) {
var culture = localisationService.getCulture();
function getUsersObservable(val) {
return rx.Observable
.fromPromise($http.get("/api/" + culture + "/usersearch", { params: { userName: val } }))
.map(function (response) {
return response.data;
});
}
$scope.close = close;
$scope.$createObservableFunction("getUsers")
.debounce(400)
.filter(function (val) {
return val.length > 0;
})
.flatMapLatest(getUsersObservable)
.subscribe();
}
]);
HTML:
<div class="form-group">
<label for="the-user" localised-text-key="TheUser"></label>
<input type="text" id="the-user" ng-model="userId" uib-typeahead="user for user in getUsers($viewValue)" typeahead-loading="loadingUsers" class="form-control" />
</div>
服务器端:
public async Task<IHttpActionResult> Get(string userName)
{
var users = await _modelContext.Users.Where(u => u.UserName.Contains(userName)).OrderBy(u => u.UserName).Select(u => u.UserName).Take(20).ToArrayAsync();
return Ok(users);
}
输入被正确去抖; JavaScript 开头的 rx.observable
将搜索结果作为字符串数组返回,并正确地去抖动输入。我不确定如何将结果打包成可以由 ui.bootstrap.typeahead 正确解释的 promise 。
最佳答案
好吧,我在文档中完全错过了它
ng-model-options $ - Options for ng-model (see ng-model-options directive). Currently supports the debounce and getterSetter options.
所以该指令允许您将选项附加到它的 ng-model
上,就像普通的 Angular 所做的那样。
因此您可以使用它为您的模型值设置 debouce,然后通过 ng-change
指令调用一个函数。
<input type="text" id="the-user"
ng-model="userId"
ng-model-options="{'debounce': 500}"
ng-change="sendHttpAfterDebounce()"
uib-typeahead="user for user in getUsers($viewValue)" typeahead-
loading="loadingUsers"
class="form-control" />
现在您的函数 (sendHttpAfterDebounce
) 将在您完成输入后运行 500 毫秒。
关于javascript - ui.bootstrap.typeahead : how to combine $http with debounce,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40126717/
在我的 html 页面中,我尝试添加 Typeahead 以进行自动完成,但我无法解决与 TypeError 和 ReferenceError 相关的问题。 我在 CodePen 上尝试了一个示例,工
我已经使用 npm 安装了 typeahead.js。根据我的阅读,这包括预输入和猎犬。 然后我在我的模块中需要 jquery 之后需要它。 但现在当我打电话 new Bloodhound() Blo
我正在尝试使用Twitter提前输入,但遇到了问题。我不知道如何提前将字符串传递给服务器。是通过GET参数吗?如果是这样,该参数的名称是什么? 最佳答案 通过GET参数最简单,您可以选择所需的任何参数
看起来 CSS 不适用于我的 Typeahead。 我正在尝试重现可滚动下拉菜单,例如 https://twitter.github.io/typeahead.js/examples 这是我的代码:
我正在这样设置 typeahead: $this.typeahead({ prefetch: $this.data('url-prefetch'),
我有一个 Typeahead 实例拉入一个列出机场的远程 JSON 对象,我需要按“位置组”将它们分组到建议中,如下图所示: ...这里是如何格式化 JSON 的示例: { "locations
作为标题,我想问:“是否可以限制预先输入显示的建议?” 例如,我有 3 个数据集,每个数据集有 10000 个结果(来自查询)。主题以字符 t 开头大约有 3000 个结果或可能更多。 如果我输入 t
我想实现的功能是,如果我点击一个 DOM 元素,它会自动填充其中包含指定值的预先输入,它应该为此触发 typeahead:selected。 我发现了很多与之相关的查询,答案是 jQuery#type
首先,请检查:http://ws.luyencong.net/data/search/query.php?do=advanced 您可以将该 JSON 的所有内容粘贴到此处:http://pro.js
我一直在尝试结合几个功能 in typeahead plugin特别是多数据集 + 空 + 默认建议。到目前为止没有运气,希望有人可以帮助 现在,为了使其工作,它是多个数据集之间的选择---或---空
我正在尝试将预输入结果放入页面上的特定 div 中。我获得了 JSON 回调数据,但我不知道如何使用它来填充特定的 div。 process 函数的唯一作用是在搜索字段下方列出结果,无论其长度如何。
正如在 screenshot - 使用 typeahead 时如何禁用自动填充? 谢谢。 附注: 使用的浏览器是 Chrome 版本 47.0.2526.106(64 位) 最佳答案 添加 autoc
正如在 screenshot - 使用 typeahead 时如何禁用自动填充? 谢谢。 附注: 使用的浏览器是 Chrome 版本 47.0.2526.106(64 位) 最佳答案 添加 autoc
我使用的是 0.11.1 版的 Twitter Typeahead。现在我正试图让远程工作正常,但不知何故我认为我的行为很奇怪。 这是使用本地数组的工作代码: var localArray = [{"
我试过在 web 应用程序中应用 twitters typeahead 插件。我使用 typeahead 插件初始化了许多 typeahead 输入字段,这似乎以某种方式起作用。该插件栩栩如生。然而,
所以我使用Materialziecss和第三方库进行标签输入 Materializecss:http://materializecss.com/ Materialize 标签库:http://henr
我想用 Typeahead JS 做一个简单的自动完成但我不能让它工作。我按照手册中的说明进行操作,但我不确定我在这里做错了什么。我无法从 json 文件中获取正确的值。它是一个带有对象的数组,我只想
我有一个 Angular uib-typeahead。这是我创建的 plunkr 的链接。 https://plnkr.co/edit/8XwhSXsZlyd0oKSljS9t?p=preview .
我实际上想发送我选择的主题(一个包含许多变量的 json 对象),而不是存储在 topicsPopulate 中的字符串(主题名称)。Topics 是一个主题数组,一个主题看起来像这样, {
我正在尝试使用带有 react-bootstrap-typeahead 的旧 jQuery typeahead 来复制搜索字段。它查询使用多个异步数据源,并显示按这些数据源的返回分组的结果。 例如,如
我是一名优秀的程序员,十分优秀!