引导AngularJS uib-typeahead上的异步请求 [英] Asynchronous request on bootstrap AngularJS uib-typeahead
问题描述
我正在尝试在服务器端搜索用户输入的名称,并使用引导程序3提供建议. uib-typeahead ,但是(尽管我对值进行了硬编码以返回-用于测试目的),但没有值返回到typeahead下拉列表.我的猜测是,由于这是一个异步请求,因此在检索请求数据时已经返回了任何数据.
I am trying to search on the server side a name entered by the user, and give suggestions using bootstrap 3 uib-typeahead, however (although I hard coded the values to return - for testing purposes), no value is returning to the typeahead dropdown. My guess is that since this is an async request, any data is already returned by the time the request data is retrieved.
在预输入监听期间,有什么方法可以从服务器端检索数据吗?
Is there any way how data could be retrieved from server side, whilst typeahead is listening?
$scope.test_search = function(test_name){
var curr_url = '/plan/ajax/test/';
var search_response = $http.get(curr_url,{
cache: true,
params:{'name': test_name, 'csrfmiddlewaretoken': $cookies.csrftoken}
}).then(function successCallback(response) {
console.log(response.data);
//return response.data;
var test = [
{country: "US", name : 'Alabama'}
];
return test;
}, function errorCallback(response) {
alert('Error');
});
},
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div class="col-lg-6">
<pre>Model: {{new_ingredient_selected | json}}</pre>
<input type="text"
ng-model = "new_ingredient_selected"
placeholder="test test"
uib-typeahead="ingredient.name for ingredient in test_search($viewValue) | filter:{name:$viewValue}"
typeahead-loading="loadingLocations"
typeahead-no-results="noResults"
typeahead-on-select="onTypeaheadIngredientSelect($item, $label, $index)"
typeahead-wait-ms ="400"
class="form-control">
<i ng-show="loadingLocations" class="glyphicon glyphicon-refresh"></i>
<div ng-show="noResults">
<i class="glyphicon glyphicon-remove"></i> No Results Found
</div>
</div>
推荐答案
当函数缺少返回语句,它将返回 When a function lacks a return statement, it returns a value of 另外,重新抛出拒绝处理程序中的错误响应.否则,被拒绝的承诺将被转换为已实现的承诺,并以 Also it is important to re-throw the error response in the rejection handler. Otherwise the rejected promise will be converted to a fulfilled promise that resolves with a value of 这篇关于引导AngularJS uib-typeahead上的异步请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! test_search
函数需要
undefined
的值.undefined
. undefined
的值进行解析.undefined
.