How do I bind to list of checkbox values with AngularJS?

前端 未结 29 2704
天涯浪人
天涯浪人 2020-11-22 05:20

I have a few checkboxes:





        
29条回答
  •  萌比男神i
    2020-11-22 06:08

    Using a string of $index can help to use a hashmap of selected values:

    This way the ng-model object gets updated with the key representing the index.

    $scope.someObject = {};
    

    After a while $scope.someObject should look something like:

    $scope.someObject = {
         0: true,
         4: false,
         1: true
    };
    

    This method won't work for all situations, but it is easy to implement.

提交回复
热议问题