我试图在Typeahead中使用Angular指令来加载和搜索我的数据库。问题是建议只显示" undefined"当我在搜索时。
我的HTML看起来像这样:
<h4>Asynchronous results</h4>
<pre>Model: {{asyncSelected | json}}</pre>
<input type="text" ng-model="asyncSelected" placeholder="Locations loaded via $http" typeahead="person for object in getLocation($viewValue)" typeahead-loading="loadingLocations" typeahead-no-results="noResults" 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>
JS:
$scope.getLocation = function(val) {
var data = {
searchString: val
};
return $http.post('/api/search', data).then(function(response){
console.log(transformSearchResults(response));
/*Returns an array of objects like this:
[
{
name: "Peter Pan",
address: "Neverland 944"
}
]
*/
return transformSearchResults(response);
});
};
我最终会尝试按名称和地址进行过滤,但我想我需要先了解基础知识。
有关如何解决此问题的任何建议将不胜感激。
答案 0 :(得分:0)
尝试分配列表
//你在这里编码
$ scope.viewvalue ='?'; $ scope.list = $ scope.getLocation($ scope.viewvalue);
// html // typeahead =“列表中对象的人”