我正在尝试通过typeahead将autocomlete添加到我的项目中,但现在它显示在Dropdown [object Object]
中。我哪里错了?
$scope.getUsers = function () {
$scope.searchRequest = "/listaccounts.php?name=" + $scope.asyncSelected;
console.log($scope.searchRequest);
return $http.get($scope.searchRequest).then(function (response) {
$scope.searchResults = response.data;
return $scope.searchResults.records;
});
};
<input type="text" ng-model="asyncSelected" ng-change="asyncSelected = asyncSelected.toLowerCase()" name="user" class="form-control" aria-describedby="basic-addon1" autocomplete="off" uib-typeahead="name for name in getUsers($viewValue)">
JSON看起来像:
{"records":[{"name":"q2q23w"},{"name":"qantheman"},{"name":"qee"},{"name":"qit"},{"name":"qiwi"}]}
我只需要在下拉列表中显示名称。
答案 0 :(得分:1)
getUsers()
正在返回一个对象数组,而typeahead似乎有问题。 @hadiJz解决方案可以工作(我不知道)或者您可以通过更改为:{/ p>从getUsers()
返回字符串列表
return $scope.searchResults.records.map(function(record) { return record.name; }));
答案 1 :(得分:0)
试试这个
uib-typeahead="name.name as name.name for name in getUsers($viewValue)">
答案 2 :(得分:0)
你可以,
<input name="records" id="records" type="text" placeholder="enter a record" ng-model="selected" typeahead="record.name for record in records | filter:$viewValue | limitTo:8" class="form-control">
<强> DEMO 强>