代码之家  ›  专栏  ›  技术社区  ›  silencedogood

将多组单选按钮值存储到object angularjs中(不带jQuery)

  •  0
  • silencedogood  · 技术社区  · 6 年前

    <tr ng-repeat="s in rollCallList">
        <td align="left">{{s.Last_Name}}, {{s.First_Name}}</td>
        <td>
             <input name="{{s.dc_number}}" id="id1{{s.dc_number}}" type="radio" value="P" ng-checked="radiocheck" />P
                    <input name="{{s.dc_number}}" id="id2{{s.dc_number}}" type="radio" value="A" />A
                    <input name="{{s.dc_number}}" id="id3{{s.dc_number}}" type="radio" value="X" />X
        </td>
    </tr>
    <tr>
        <td colspan="2">
               <button class="btn" ng-show="SaveAttBtn" ng-click="SaveAtt(RollCallDate)">Save Attendance</button>
               <button class="btn" ng-show="DeleteAttBtn" ng-click="DeleteAtt(RollCallDate)">Delete Attendance</button>
        </td>
    </tr>
    
    $scope.SaveAtt = function (dt) {
            $scope.rollCallList.forEach(function (obj) {
    
                var dc = obj.dc_number;
                var attVal = $('input[name=' + dc + ']:checked').val();
    
                obj.status = attVal;
                obj.classDate = dt;
    
                console.log(obj);
            });
        }
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   Axar    6 年前
    <input name="dcNumber_{{s.dc_number}}" type="radio" ng-model="s.status" ng-value="'P'" />P
    <input name="dcNumber_{{s.dc_number}}" type="radio" ng-model="s.status" ng-value="'A'" />A
    <input name="dcNumber_{{s.dc_number}}" type="radio" ng-model="s.status" ng-value="'X'" />X
    

    在你的物品中循环时, s.status