[英]Angular: ng-options in ng-repeat
I have a collection of request and each request has collection of status. 我有一个请求集合,每个请求都有状态集合。 I am trying to create a dropdown for each request and populate with their statuses. 我正在尝试为每个请求创建一个下拉列表,并填充其状态。 How can I read the selected status for each request? 如何读取每个请求的选定状态?
Sample controller is: 样本控制器为:
// Code goes here
var app = angular.module('demo', []);
app.controller('myController', function($scope){
$scope.requests=[{"name": "Request1",
"statusList": [{ "name": "status1", "isSelected": true },
{ "name": "status2", "isSelected": false }
]
},{"name": "Request2",
"statusList": [{ "name": "status3","isSelected": false },
{ "name": "status4", "isSelected": false }
]
}];
});
and sample html: 和示例html:
<div class="container" ng-controller="myController">
<div>
<ul ng-repeat="request in requests">
{{request.name}}
<li>
<select class="form-control" ng-options="status as status.name for status in request.statusList" ng-model="selectedStatus"></select>
</li>
</ul>
</div>
</div>
The plunker is here: http://plnkr.co/edit/KkYgCDTWbWuorTOQISPo?p=preview 窃听器在这里: http ://plnkr.co/edit/KkYgCDTWbWuorTOQISPo?p=preview
create model with request
instance 用request
实例创建模型
like this 像这样
ng-model="request.selectedStatus"
Then you can read it from $scope.requests
然后您可以从$scope.requests
读取它
Just use request.selected in ng-model, since your request in HTML is referencing to each group, your selected will be a new key created in that array that will contain the selected one. 只需在ng-model中使用request.selected,因为HTML中的请求将引用每个组,因此您选择的将是在该数组中创建的新键,其中将包含所选的键。
ng-model= "request.selected"
http://plnkr.co/edit/AaDl0idgtKmo5vLGdp7h http://plnkr.co/edit/AaDl0idgtKmo5vLGdp7h
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.