Select-UI未填充下拉列表

时间:2017-10-24 14:14:22

标签: angularjs angular-ui-select

我尝试使用AngularJS Select-UI,但我在填充下拉列表时遇到问题。控制台上没有显示错误,但下拉菜单没有填充:

HTML部分

                            <ui-select ng-model="selectedUser" theme="bootstrap" on-select="onSelectCallback($item)">
                            <ui-select-match placeholder="Select a User">{{selectedUser.username}}</ui-select-match>
                            <ui-select-choices repeat="item in options.people">
                                <div ng-bind-html="item.username | highlight: $select.search"></div>
                            </ui-select-choices>
                        </ui-select>

控制器部分:

function selectCtrl($scope, $http) {

$scope.options = {};
$scope.selectedUser = {};


var onUserComplete = function(response){
    $scope.options.people = response.data;
    console.log($scope.options.people);

}

$http.get("http://localhost/api/user")
    .then(onUserComplete);


$scope.onSelectCallback = function(item){
    $scope.selectedUser = item;
}

}

数据以数组形式返回,我在控制台注销后查看:

Array(2)
0:{id: 1, username: "username1", $$hashKey: "object:130"}
1:{id: 2, username: "username2", $$hashKey: "object:131"}
length:2
__proto__:Array(0)

1 个答案:

答案 0 :(得分:0)

你试过简化版吗?

e.g:

ng-bind="item.username"

甚至直接定义$scope.options = {};(也许错误不在then方法中。

相关问题