简体   繁体   English

使用angular.js ui和bootstrap typeahead进行异步调用以检索自动搜索建议

[英]using angular.js ui and bootstrap typeahead for asynchronous call to retrieve auto suggestions for search

I am using angular 1.3.0 and bootstrap 3.2.0. 我使用角1.3.0和bootstrap 3.2.0。 I am trying to get data from asynchronously from my mysql database but I got some issue with bootstrap typeahead. 我试图从我的mysql数据库异步获取数据,但我遇到了bootstrap typeahead的问题。

MY code index.html: 我的代码index.html:

<input type="text" ng-model='locality' name="locality" typeahead="name for locality in getLocality($viewValue) | filter:$viewValue" typeahead-loading="loadingLocations" class="form-control size1 input-medium search-query"
    placeholder="Enter Organization name/service">
</input>

main.js file for typeahead typeahead的main.js文件

    $scope.getLocality = function(val) {
       console.log(val);
       var url = $rootScope.baseURL + '/api/location?locality=' + val;
       console.log(url);
       return $http.get(url, {
           params: {
               name: val,
               sensor: false
           }
       }).then(function(response) {
           var addresses = [];
           angular.forEach(response.data.resulults, function(item) {
               addresses.push(item.formatted_name);
           });
           return addresses;
       });

    };

When I was debugging this value will fine but i am not getting any auto suggestions please any one help me out of this problem. 当我调试这个值时会很好,但我没有得到任何自动建议请任何人帮我解决这个问题。

It's working fine Thank u @tiblu 它工作得很好谢谢你@tiblu
index.html file index.html文件

<input type="text" ng-model='locality' name="locality"
                                typeahead="name for name in getLocality($viewValue)"
                                typeahead-loading="loadingLocations"
                                class="form-control size1 input-medium search-query"
                                placeholder="Enter Organization name/service">
                                </input>



    .js file    


    $scope.getLocality=function(val){
                        console.log(val);
                                    var url=$rootScope.baseURL + '/api/location?locality='+val;
                                console.log(url);
                                              return $http.get(url,{

                                                           params: {
                                                                     name: val,
                                                                     sensor: false
                                                                     }
                                                                 }).then(function(response){
                                                                    console.log(response);
                                                                    console.log(response.data); 
                                                                    var addresses=[];
                                                                           angular.forEach(response.data.data,function(item){
                                                                            addresses.push(item.name);
                                                                            //return item.formatted_name;
                                                                            console.log(response.data);
                                                                           });
                                                                          return addresses;
                                                                         /*return response.data.results.map(function(item){
                                                                           return item.formatted_address;*/
                                                                  });

                    };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM