【发布时间】:2017-04-24 06:19:13
【问题描述】:
我是 Angular JS 的新手。我有以下复选框,数据来自网络服务:
<label ng-repeat="r in MedicalConditions track by $index">
<input ng-model="ids[$index]" type="checkbox" ng-checked="r.value">
{{r.conditions_name}}
</label>
console.log 中的值完全符合我的要求。如何将值推送到数组,即 arr[] 并将其字符串化。我试过这样的代码..
//获取医疗条件列表
$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);
【问题讨论】:
-
@Sinchan $scope.lists[] 在我的案例中分配,数据来自动态..在我的案例中该怎么做..
-
你能做一个小提琴吗?
-
您应该先尝试使用 ng-model 绑定动态复选框值。然后其他事情会更容易做。
标签: javascript angularjs arrays json