gpt4 book ai didi

javascript - Angucomplete-alt : Remote-API-handler not working as expected

转载 作者:行者123 更新时间:2023-11-29 10:11:43 24 4
gpt4 key购买 nike

我在 AngularJS 项目中使用 angucomplete-alt ( https://github.com/ghiden/angucomplete-alt ),但我似乎无法让它工作。

我正在尝试构建一个非常简单的自动完成表单,如下所示:

<angucomplete-alt pause="400" selected-object="obj" remote-api-handler="search" title-field="id" minlength="1" />

我的函数在 Controller 中定义如下:

    $scope.search= function (userInputString, timeoutPromise) {
return $timeout(function () {
return [{ "id": "1" }, { "id": "2" }, { "id": "3" }]
}, 1000);

但是,每次我尝试搜索时,我都会得到“无结果”,即使控制台没有记录任何错误并且该函数被正常调用也是如此。我做错了什么?

最佳答案

好的,我找到了解决方案。即使在文档中根本没有指定,该指令也需要这样的响应:

{"data": [Array of objects]}

因此,如果我这样做,它会起作用:

$scope.search= function (userInputString, timeoutPromise) {
return $timeout(function () {
return {"data": [{ "id": "1" }, { "id": "2" }, { "id": "3" }]};
}, 1000);

希望对其他人有帮助。

关于javascript - Angucomplete-alt : Remote-API-handler not working as expected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32251694/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com