AngularJS 复选框 ng-model 作为数组

问题描述 投票:0回答:1

我的 HTML 是

    <label>
  <input type="checkbox" name="Communities" ng-model="formData.User.Communities" value="1" id="YOURROLE_0">
  COACH</label>
<br>
<label>
  <input type="checkbox" name="Communities" ng-model="formData.User.Communities" value="2" id="YOURROLE_1">
  ATHLETE</label>
<br>
<label>
  <input type="checkbox" name="Communities" ng-model="formData.User.Communities" value="3" id="YOURROLE_2">
  PARENT</label>

如何指定我获得模型的 HTML/Javascript,如下所示。我需要将复选框(选中的复选框)作为数组填充到数组中。

.controller('formController', function($scope) {

        $scope.formData = {
            "User": {
                "Communities": [1, 2, 3]
            }
        };

    });
javascript angularjs angular-ngmodel
1个回答
2
投票
© www.soinside.com 2019 - 2024. All rights reserved.