5

我正在尝试使用 Angular UI typeahead。我的问题是下拉菜单没有显示。正在正确调用远程数据并正在返回数据...但下拉列表拒绝显示...

<td colspan="5">
   <pre>Model: {{selected| json}}</pre>
   <input id="AutoCompleteDebtor" 
          type="text" 
          data-ng-model="selected" 
          data-typeahead="debtor for debtor in Debtors($viewValue)" 
          class="form-control input-sm" 
          placeholder="Enter 3 letters of Debtor Name" />
</td>

更新:好的 - 它适用于字符串名称数组,但我如何处理对象?

<!DOCTYPE html>
<html data-ng-app="myApp">
<head>
<title>Angular Typeahead</title>
<link href="Content/bootstrap/bootstrap.min.css" rel="stylesheet" />
<script src="Scripts/angular.min.js"></script>
<script src="Scripts/ui-bootstrap-tpls-0.6.0.min.js"></script>
<script>
    angular.module('myApp', ['ui.bootstrap'])
    .controller('SimpleController', function ($scope) {
        $scope.people = [
            { name: 'Alan', age: 23 },
            { name: 'Bruce', age: 24 },
            { name: 'Celine', age: 53 },
            { name: 'Dan', age: 43 },
            { name: 'Eric', age: 23 },
            { name: 'Freda', age: 47 },
            { name: 'Greg', age: 73 },
            { name: 'Hanna', age: 27 }
        ];
    });
</script>

</head>
<body data-ng-controller="SimpleController">
<div>
    <pre>Model: {{selected| json}}</pre>
    <input type="text" data-ng-model="selected" data-typeahead="name for name in people | filter:$viewValue | limitTo:8">
</div>
</body>
</html>

我一直在关注https://github.com/angular-ui/bootstrap/tree/master/src/typeahead示例

4

2 回答 2

1

我在这个小提琴上找到了答案:http: //jsfiddle.net/ukAc5/1/

data-typeahead="n.name for n in people
于 2013-10-12T18:53:43.603 回答
0

我从 Greg 的回答中解决了我的输入问题。这是我为预先输入所做的(希望这对某人有所帮助):

typeahead="i.t_UserName for i in employeeInfo | filter:$viewValue | limitTo:4" 作为您的 html 输入的属性

并在您的控制器中(使用员工资源)

$scope.employeeInfo = getEmployeeResourceSvc.getEmplInfo.query(function(response){
          $scope.employeeInfo= response;
});
于 2014-03-10T15:55:19.537 回答