Javascript 如何使用Angular JS从复选框中获取选中值

Javascript 如何使用Angular JS从复选框中获取选中值,javascript,angularjs,arrays,json,Javascript,Angularjs,Arrays,Json,我是新来的。我有以下复选框,数据来自web服务: <label ng-repeat="r in MedicalConditions track by $index"> <input ng-model="ids[$index]" type="checkbox" ng-checked="r.value"> {{r.conditions_name}} </label> 这可能有助于: angular.module('app',

我是新来的。我有以下复选框,数据来自web服务:

 <label ng-repeat="r  in MedicalConditions track by $index">
    <input ng-model="ids[$index]" type="checkbox" ng-checked="r.value"> 
       {{r.conditions_name}}
    </label>
这可能有助于:

angular.module('app',[])
.controller('controller',function($scope){
$scope.ids={};
$scope.arr={};
$scope.MedicalConditions={};
$scope.MedicalConditions[0]={};
$scope.MedicalConditions[0]。值=true;
$scope.MedicalConditions[0]。条件_名称='first value';
$scope.MedicalConditions[1]={};
$scope.MedicalConditions[1]。值=false;
$scope.MedicalConditions[1]。条件_name='seconde value';
$scope.$watchCollection('id',函数(newVal){
$scope.parameter.class0=$scope.ids;
});
$scope.parameter={};
$scope.parameter.firstname='dummy name';
$scope.parameter.class0=$scope.ids;
});

{{r.conditions_name}}

参数:{{Parameter}}
这可能会有帮助:

angular.module('app',[])
.controller('controller',function($scope){
$scope.ids={};
$scope.arr={};
$scope.MedicalConditions={};
$scope.MedicalConditions[0]={};
$scope.MedicalConditions[0]。值=true;
$scope.MedicalConditions[0]。条件_名称='first value';
$scope.MedicalConditions[1]={};
$scope.MedicalConditions[1]。值=false;
$scope.MedicalConditions[1]。条件_name='seconde value';
$scope.$watchCollection('id',函数(newVal){
$scope.parameter.class0=$scope.ids;
});
$scope.parameter={};
$scope.parameter.firstname='dummy name';
$scope.parameter.class0=$scope.ids;
});

{{r.conditions_name}}

参数:{{Parameter}}
试试下面的方法

var-app=angular.module('exApp',[]);
应用程序控制器('ctrl',函数($scope){
$scope.ids=[];
$scope.arr=[];
$scope.checkSelected=[];
$scope.MedicalConditions=[{“条件名称”:“xxz”,“条件id”:“1”},{“条件名称”:“yyz”,“条件id”:“2”},{“条件名称”:“zzz”,“条件id”:“3”}];
$scope.$watchCollection('id',函数(newVal){
对于(变量i=0;i-1){
$scope.checkSelected.splice(idx,1);
checked.check=false;
}
//加
否则{
$scope.checkSelected.push(选中);
checked.check=true;
}       
$scope.checkAll=$scope.checkSelected.length==$scope.MedicalConditions.length?true:false;
};
变量参数={
“first_name”:$scope.first_name,
“中间名称”:$scope.middle\u name,
//“0类”:/*字符串化数据,即arr[]*/
};
});

全选:
{{r.conditions_name}}

{{checkSelected}}
试试下面的方法

var-app=angular.module('exApp',[]);
应用程序控制器('ctrl',函数($scope){
$scope.ids=[];
$scope.arr=[];
$scope.checkSelected=[];
$scope.MedicalConditions=[{“条件名称”:“xxz”,“条件id”:“1”},{“条件名称”:“yyz”,“条件id”:“2”},{“条件名称”:“zzz”,“条件id”:“3”}];
$scope.$watchCollection('id',函数(newVal){
对于(变量i=0;i-1){
$scope.checkSelected.splice(idx,1);
checked.check=false;
}
//加
否则{
$scope.checkSelected.push(选中);
checked.check=true;
$scope.parameter = "{}";
$scope.class0 = "{}";
$http.get('http://192.168.1.129:8080/apartment//member/medical/conditions/list').then(function(response) {
    $scope.MedicalConditions = response.data.list;
});

  $scope.$watchCollection('ids', function(newVal) {     
       $scope.parameter.class0 = $scope.ids;
    }); 


$scope.alertdata = function() {
    var parameter = {
        "first_name": $scope.first_name,

        "role": [{
            "role_id": 1,
            "name": "Admin",
            "details": "text"
        }],
        "associated": [{
            "associated_id": 1,
            "associated_name": "Parent",
            "primary_member_id": 1
        }],
        "class0": $scope.ids
    }
    parameter = JSON.stringify(parameter);
<label ng-repeat="r  in MedicalConditions track by $index">
<input ng-model="ids[$index]" type="checkbox" ng-change="valCh(r)"> {{r.conditions_name}}
</label>
var postApp = angular.module('EntityApp', []);
postApp.controller('EntityAppCntroller', function($scope, $http, $window, $timeout, $location) {

    //To fetch Medical Conditions List    
        $http.get('http://111.222.444:8080/apartment//member/medical/conditions/list').then(function(response) {
            $scope.MedicalConditions = response.data.list;
        });
        var list = [];
        $scope.valCh = function(value) {
            list.push(value);
            JSON.stringify(list);
        }

        $scope.alertdata = function() {
            var parameter;
            parameter = {
                "parameter": {
                    "first_name": $scope.first_name,
                    "medicalconditions": list
                }
            }
            $http({
                url: 'http://111.222.333:8080/apartment//save/member/details',
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                data: JSON.stringify(parameter)
            }).success(function(data, status) {
                if (data.status == 'success') {
                    alert("User Created");
                    $location.reload();
                } else if (data.status == 'failure') {
                    alert("Some failure please try again later !!!");
                }
            });
        };
    });
<div ng-app="myApp" ng-controller="MyCtrl">
    <label ng-repeat="r in MedicalConditions track by $index">
    <input ng-model="ids[$index]" 
      ng-init="ids[$index] = r.value"
      type="checkbox"> 
    {{r.condition}}
  </label>
</div>
var myApp = angular.module('myApp', []);

myApp.controller('MyCtrl', function($scope){
    $scope.ids = [];

    $scope.MedicalConditions = [{
    _id: 1,
    value: true,
    condition: 'Condition 1'
  }, {
    _id: 2,
    value: false,
    condition: 'Condition 2'
  }, {
    _id: 3,
    value: true,
    condition: 'Condition 3'
  }];
});