Typeahead中的问题

时间:2014-02-26 20:16:37

标签: angularjs

我遇到了 angular Typeahead 的问题。一旦用户开始输入,我就会调用一个宁静的服务,并且从REST响应中我创建了一个字符串,它是“name + person id + city + phone”的组合,应该是在UI处显示为建议。

我能够成功调用RESTful服务,并从响应中创建一个类似于此的字符串列表

 ["Tom,Alison ,00017556,Dulles,9988776655",
  "alice,Ali,00114088,Dulles,9988776655",
  "Vipin,Nambi,00034585,Dulles,9988776655",
  "David,Alison,00091141,Dulles,9988776655"
] 

我也可以使用console.log打印它,但我在UI上看不到任何内容。我试图调用另一个开源REST服务“http://gd.geobytes.com/”,它工作正常,我可以在UI中看到城市列表[请参阅注释代码]。我试图从geoBytes服务打印response.data,它在控制台上看起来像这样

Alice, TX, United States,
Aliceville, AL, United States,
Alicia, AR, United States,
Alief, TX, United States,
Aline, OK, United States,Aliquipp

和浏览器上的这个一样

JSON_CALLBACK(["China Grove, NC, United States","China Spring, TX, United States","China, ME, United States","China, TX, United States","East China, MI, United States","South China, ME, United States"]);

我无法理解它是否适​​用于geoBytes REST服务,那么我的服务有什么问题。我怀疑使用limitToFilter返回数据有什么问题(JSON.stringify(searchingPersonList)但我无法解决。有人可以帮我这里。

的index.html

 <input type="text" placeholder="Search" ng-model="result" typeahead="suggestion for suggestion in person($viewValue) | filter:$viewValue">

控制器

 $scope.person = function(searchString) {

    PersonDataService.getPersonForSearchString(searchString)
    .then(function (data)
    {
     var searchedPersonList = [];

    for(var i=0;i <data.SearchPersonResponse.Person.length ;i++ )
    {

    searchedPersonList .push( data.SearchPersonResponse.Person[i].FullName  + "," + 
data.SearchPersonResponse.Person[i].PersonID  + "," +

data.SearchPersonResponse.Person[i].City + "," +

data.SearchPersonResponse.Person[i].Phone  );

    }
    console.log ("The list prepared is " +JSON.stringify(searchedPersonList ));

    return limitToFilter(JSON.stringify(searchedPersonList ) , 15);
    },

    function (error)
    {
     alert("Invocation of REST service failed " + error.data);
    });



       /*
        This works

    return $http.jsonp("http://gd.geobytes.com/AutoCompleteCitycallback=JSON_CALLBACK&filter=US&q="+searchString)
    .then(function(response)
    {
    console.log("geoBytes " + response.data);
    return limitToFilter(response.data, 15);
    });

    */

    };

1 个答案:

答案 0 :(得分:1)

您还必须返回整个服务电话,在服务之前添加return

return PersonDataService.getPersonForSearchString(searchString)....

另外,如评论(searchedPersonList

中所述,返回非字符串化对象