首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在ng中继器Angularjs中处理单选按钮组

如何在ng中继器Angularjs中处理单选按钮组
EN

Stack Overflow用户
提问于 2016-06-27 03:20:09
回答 1查看 94关注 0票数 0

我有一个页面,我需要提交所有需要退休或不退休的员工。我正在尝试显示每个员工的员工姓名和单选按钮列表,并提供退休和不退休选项。

代码语言:javascript
复制
<div class="body" ng-repeat="employee in EmployeesList">
   <div class="row" style="padding-left: 15px;">            
     <label>{{employee.name}}</label>     
   </div>
   <div class="row">
     <label class="radio-inline"><input name="radioGroup" type="radio" id="Retired" 
       checked="checked" ng-model="$parent.status" value="RETIRED"/><strong>RETIRED</strong></label>
     <label class="radio-inline"><input name="radioGroup" type="radio" id="NotRetiring"
       ng-model="$parent.status" value="NOTRETIRING"/><strong>NOT RETIRING</strong></label>
   </div>
</div>
<div class="footer">
   <button type="button" class="btn btn-default" ng-click="Submit()">OK</button>
   <button type="button" ng-click="cancel()">CANCEL</button>
</div>


Controller:

 $scope.EmployeesList = EmployeeService.getEmployeeList();

 $scope.Submit = function () {

        angular.forEach($scope.EmployeesList, function (employee, index) {                                                          
            var employeeid = employee.id;
            var date = new Date();
             
            var employeeResponse =
            {
                EmployeeID: employeeid,
                DateEntered: date,
                Status: $scope.status
            }
            
            EmployeeService.Submit(employeeResponse).then(function() {
                
            });
        }
});

当我尝试选择每个员工的状态时,无论他是不是退休了,它都不是它应该做的。如果我更改了第二个员工的状态,则第一个员工的状态将丢失其状态。现在,我需要将“退休”作为所有员工的默认选择,并需要根据需要修改每个员工的状态。请帮帮我。

EN

回答 1

Stack Overflow用户

发布于 2016-06-27 03:47:42

您希望记住每个员工的状态,因此可以尝试:

代码语言:javascript
复制
<div class="body" ng-repeat="employee in EmployeesList">
   <div class="row" style="padding-left: 15px;">            
     <label>{{employee.name}}</label>     
   </div>
   <div class="row">
     <label class="radio-inline"><input name="radioGroup" type="radio" id="Retired" 
       checked="checked" ng-model="employee.status" value="RETIRED"/><strong>RETIRED</strong></label>
     <label class="radio-inline"><input name="radioGroup" type="radio" id="NotRetiring"
       ng-model="employee.status" value="NOTRETIRING"/><strong>NOT RETIRING</strong></label>
   </div>
</div>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38042317

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档