我需要使用此对象中的select选项在下拉列表中显示类别值:
[{
"_id": "57b4508923a10cd83c79a301",
"created_by": "1",
"category": "Criminal law",
"__v": 0,
"delete_status": "0",
"active_status": "1",
"modified_date": "1471434889599",
"created_date": "1471434889599"
}, {
"_id": "57b466b34f94fc982a0d926d",
"created_by": "1",
"category": "Business Law",
"__v": 0,
"delete_status": "0",
"active_status": "1",
"modified_date": "1471440563159",
"created_date": "1471440563158"
}, {
"_id": "57c6be3ae74cdc1d6a9b2224",
"created_by": "1",
"category": "Corporate Law",
"__v": 0,
"delete_status": "0",
"active_status": "1",
"modified_date": "1472642618768",
"created_date": "1472642618768"
}]
我使用下面的代码,但未定义:
<select ng-model="category" ng-options="users.id as users.category for item in items"></select>
任何人都可以帮助我吗?
答案 0 :(得分:1)
试试这个
var app = angular.module('app', []).controller('countryCtrl', ['$scope',
function($scope) {
$scope.records = [{
"_id": "57b4508923a10cd83c79a301",
"created_by": "1",
"category": "Criminal law",
"__v": 0,
"delete_status": "0",
"active_status": "1",
"modified_date": "1471434889599",
"created_date": "1471434889599"
}, {
"_id": "57b466b34f94fc982a0d926d",
"created_by": "1",
"category": "Business Law",
"__v": 0,
"delete_status": "0",
"active_status": "1",
"modified_date": "1471440563159",
"created_date": "1471440563158"
}, {
"_id": "57c6be3ae74cdc1d6a9b2224",
"created_by": "1",
"category": "Corporate Law",
"__v": 0,
"delete_status": "0",
"active_status": "1",
"modified_date": "1472642618768",
"created_date": "1472642618768"
}];
}
])
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="countryCtrl">
<select ng-init="text._id = records[0]._id" ng-model="text" ng-options="record.category for record in records track by record._id">
</select>
</div>
答案 1 :(得分:0)
<select ng-model="category" ng-options="item.id as item.category for item in items"></select>
只需在模板中更新(y):)