在 AngularJS 文档中,他们引用了这个 fiddle ,我从这里得到了一个简单的 jsfiddle 。
整个 HTML:
<body ng-app="demoApp">
<div ng-controller="demoController">
<table>
<tr>
<td>Select Category
<select ng-model="selectedCategory"
ng-options="cat as cat for cat in categories">
</select>
</td>
The category selected is: {{selectedCategory}}
</tr>
<tr>
<td>Select CategoryId
<select ng-model="selectedCatId"
ng-options="ds as ds.id for ds in dataset">
</select>
The category id selected is: {{selectedCatId}}
</td>
</tr>
</table>
</div>
</body>
AngularJS 控制器:
angular.module('demoApp', []).controller('demoController', function($scope) {
$scope.categories = ["CAT1", "CAT2", "CAT3"];
$scope.dataset = [
{ "category": "CAT1", "id": "CAT_ID11" },
{ "category": "CAT1", "id": "CAT_ID12" }
];
$scope.selectedCategory = categories[1];
$scope.selectedCatId = $scope.dataset[1];
});
我在小提琴中看到的结果:
除了没有看到初始化之外,我也没有看到列表项,也不知道为什么。我错过了什么?