gpt4 book ai didi

javascript - typeahead 无法从 api angularjs 获取数据

转载 作者:行者123 更新时间:2023-12-03 05:53:29 24 4
gpt4 key购买 nike

这是我的 html 代码

<input type="text" ng-model="ngModelOptionsSelected" 
placeholder="Enter Story Title"
ng-model-options="modelOptions"
ng-change="onChangeFunction()"
typeahead-on-select="typeaheadOnSelectFunction()"
uib-typeahead="document as document.Name for document in getStory($viewValue)"
class="form-control">

这是我的 .js 代码

$scope.getStory = function (val) {
storyService.GetStoryByName(cacheService.project.projectId,val).success(function (data) {
if (data.ResponseStatus) {
debugger;
return data.ResponseData;
} else {
//On failure
toastr.error(data.ErrorData.Error);
}
});
};

函数输出返回如下数据响应数据 =

[{"Id":211380.0,"Name":"dixit"},{"Id":211488.0,"Name":"dixit ade"},{"Id":251541.0,"Name":"dixit"},{"Id":842671.0,"Name":"dixit"},{"Id":842672.0,"Name":"dixit choksi"}]

但我无法在预先输入中绑定(bind)数据。

请帮助我,我被困住了。谢谢

最佳答案

您的函数 $scope.getStory() 实际上不会返回任何内容,您的返回行 return data.ResponseData; 嵌套在另一个函数中。

uib-typeahead 指令能够与 Promise 一起使用,因此您只需从函数中返回 Promise。

$scope.getStory = function (val)
{
return storyService.GetStoryByName(cacheService.project.projectId, val).success(function (data)
{
if (data.ResponseStatus)
return data.ResponseData;

toastr.error(data.ErrorData.Error);

return [];
});
};

您还可以向指令添加另一个属性,typeahead-loading="isLoading",该属性将在 Promise 解析时进行切换。例如,它可用于显示/隐藏加载旋转器!

关于javascript - typeahead 无法从 api angularjs 获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40045866/

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