如何为多选复选框选中的值传递多个值:
我的多选下拉列表应该只在下拉列表中列出RewardCode,但是当选中该复选框时,我必须将所有其他人传递回角度为json,但截至目前我只能传递一个值:
我的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>
Angular Code:
$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);
};