我已经完成了以前的解决方案,但这无助于解决我的问题。我正在尝试在typeahead中显示用户详细信息列表。我收到如下错误,API调用的结果会在控制台日志中打印出来但未显示在下拉列表中。
在我的控制器中:
$scope.getUserDetails = function (id, value) {
var myUrl = '//myAPIcall?id=1&value=xxx';
return $http.get(myUrl).then(function successCallback(response) {
return response.data.userOptions[0].userOptionValues.map(function(item) {
console.log('item.userValue = '+item.userValue);
$scope.getUserDetails = item.userValue;
return item.userValue;
});
}, function errorCallback(response) {
console.log(response);
});
};
在我的HTML中:
<input id="inputText"
type="text"
name="filter"
class="form-control"
data-ng-model="selectedVal"
uib-typeahead="item.userValue for item in getUserDetails(1,$viewValue) | filter:$viewValue | limitTo:10 "
typeahead-template="displayTemplate.html"/>
<script type="text/ng-template" id="displayTemplate.html">
<a>
<span bind-html-unsafe="match.label | uibTypeaheadHighlight:query"></span>
</a>
</script>
错误:[filter:notarray] http://errors.angularjs.org/1.4.6/filter/notarray?p0=%7B%22%24%24state%22%3A%7B%22status%22%3A0%7D%7D at angular.min.js:6 at angular.min.js:149 at Object.fn [as source](eval at compile(angular.min.js:212),:4:610 )在getMatchesAsync(ui-bootstrap-tpls-0.14.0.min.js:6747)at ui-bootstrap-tpls-0.14.0.min.js:6845 at angular.min.js:146 at e(angular.min) .js:43)在angular.min.js:45
任何帮助表示赞赏!
一些不稳定的事情正在继续:
return response.data.userOptions[0].userOptionValues.map(function(item) {
console.log('item.userValue = '+item.userValue);
$scope.getUserDetails = item.userValue; // (1)
return item.userValue; // (2)
});
1)您将$ scope.getUserDetails重置为单个值,该值将覆盖$ scope.getUserDetails = function(...)行。
2)你正在返回一个单值的数组,但在你的uib-typeahead中你试图使用item.userValue,但由于这行item = item.userValue
没有更多信息或示例数据,任何其他事情都很难说清楚。