问题描述
我正在使用 angucomplete-alt (https://github.com/ghiden/angucomplete-alt) 在一个 AngularJS 项目中,但我似乎无法让它工作.
I'm using angucomplete-alt (https://github.com/ghiden/angucomplete-alt) in an AngularJS project, however I can't seem to make it work.
我正在尝试构建一个非常简单的自动完成表单,如下所示:
I'm trying to build a really simple autocomplete form, like this:
<angucomplete-alt pause="400" selected-object="obj" remote-api-handler="search" title-field="id" minlength="1" />
我的函数在控制器中定义如下:
And my function is defined in the controller as such:
$scope.search= function (userInputString, timeoutPromise) {
return $timeout(function () {
return [{ "id": "1" }, { "id": "2" }, { "id": "3" }]
}, 1000);
然而,每次我尝试搜索时,我都会得到无结果",即使控制台没有记录错误并且函数被调用得很好.我做错了什么?
However, everytime I try to search, I get "No results", even though the console logs no errors and the function is being called fine. What am I doing wrong?
推荐答案
好的,我找到了解决方案.即使在文档中根本没有指定它,该指令也期望得到如下响应:
Ok, I've found a solution. Even though it's not specified at all in the docs, the directive expects a response like:
{"data": [Array of objects]}
因此,如果我这样做,它会起作用:
Therefore, it works if I do it like:
$scope.search= function (userInputString, timeoutPromise) {
return $timeout(function () {
return {"data": [{ "id": "1" }, { "id": "2" }, { "id": "3" }]};
}, 1000);
希望能帮到别人.
这篇关于Angucomplete-alt:远程 API 处理程序未按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!