【发布时间】:2016-02-11 20:37:46
【问题描述】:
所以我的应用程序获得了Primary Resources 的列表。这些 JSON 对象包含一个 ID、Name 和一个 role 对象数组。每个role 对象都有一个value 和name。当用户从选择标签中选择Primary Resource 时,我需要另一个选择标签来填充他们的role 值,因为一些Primary Resources 有多个roles。看起来是对的,但显然有问题。
HTML:
<div ng-controller="NewTicketCtrl">
<div class="form-group col-xs-4">
<div class="input-group">
<label for="primaryResource"><i class="fa fa-user fa-lg"></i> Primary Resource</label>
</div>
<select class="form-control" id="primary" ng-model="option.primary" ng-options="primary.id as primary.name for primary in primaryResources">
</select>
</div>
<div class="form-group col-xs-4">
<div class="input-group">
<label for="role"><i class="fa fa-briefcase fa-lg"></i> Role</label>
</div>
<select class="form-control" id="role" ng-model="option.role" ng-options="primary.role.value as primary.role.name for primary in primaryResources | filter:{primary:option.primary}">
</select>
</div>
</div>
控制器:
app.controller('NewTicketCtrl', ['$scope', '$http', function($scope, $http){
//Gets data from a JSON file
$http.get('res/formValues.json').success(function(data){
$scope.formValues = data;
//For simplicity purposes, I'm hard coding in the values
$scope.primaryResources = {
"id" : 1,
"name" : "Smith, John",
"role" : [
{
"value" : 1,
"name" : "Technician"
},
{
"value" : 5,
"name" : "Administration"
}
]
},
{
"id" : 2,
"name" : "Smith, Jane",
"role" : [
{
"value" : 1,
"name" : "Technician"
},
{
"value" : 2,
"name" : "Level 2 Technician"
},
{
"value" : 3,
"name" : "Level 3 Technician"
}
]
}
//Used to store values for later use
$scope.option = {
status : $scope.formValues.status[0].value,
priority : $scope.formValues.priority[0].value,
ticketType : $scope.formValues.ticketType[0].value,
workQueue : $scope.formValues.workQueue[0].value,
primary : $scope.formValues.primaryResource[0].id,
role : $scope.formValues.primaryResource[0].role[0].value
};
}).error(function(data){
console.log(data);
});
}]);
【问题讨论】:
标签: angularjs angularjs-filter