0

如何为多选复选框的选中值传递多个值:

我的多选择下拉列表应仅在下拉列表中列出奖励表,但是当检查该复选框时,我必须将所有其他内容作为JSON回到Angular,但是到目前为止,我只能传递一个值:

我的json:

{
    "Reward": [{
        "RewardType": 1,
        "RewardTypeValue": "PartCodes",
        "RewardCode": "CB_USD_20_US",
        "DiscountValue": 20.0
    },
    {
        "RewardType": 1,
        "RewardTypeValue": "PartCodes",
        "RewardCode": "CB_USD_30_US",
        "DiscountValue": 30.0
    },
    {
        "RewardType": 1,
        "RewardTypeValue": "PartCodes",
        "RewardCode": "CB_USD_40_US",
        "DiscountValue": 40.0
    },
    {
        "RewardType": 1,
        "RewardTypeValue": "PartCodes",
        "RewardCode": "CB_USD_50_US",
        "DiscountValue": 50.0
    }]

} 

html代码:

<li ng-repeat="reward in RewardsList ">
           <input id="{{reward.RewardCode}}.{{reward.RewardType}}"
                  type="checkbox"
                  ng-checked="selection.indexOf(reward.RewardCode) > -1"
                  ng-click="toggleSelection(reward.RewardCode)"
                  value="{{reward.RewardCode}}" /> 
    <label  for="{{reward.RewardCode}}">{{reward.RewardCode}}</label>
    </li>

角代码:

$scope.rewards = [];
$scope.toggleSelection = function toggleSelection(selectedRewards) {
   var idx = $scope.rewards.indexOf(selectedRewards);
   console.log(selectedRewards);

   // is currently selected
   if (idx > -1) {
     $scope.rewards.splice(idx, 1);
   }

   // is newly selected
   else {
     $scope.rewards.push(selectedRewards);
   }
   console.log($scope.rewards);
};
4

0 回答 0