多项选择不突出显示的项目

时间:2019-04-08 08:25:25

标签: javascript html css angularjs

我已将全选按钮添加到多选中。问题是,如果我单击“全选”按钮,则所有项目都会被选中,但不会突出显示。

这是我的代码:

<div class="label_hd">Profiles* {{user.profile}}
    <input type="button" id="select_all" ng-click="selectedAll()"
           name="select_all" value="Select All" style="margin-left: 10px">
</div>
<select multiple class="browser-default" name="userprofile"
        id="userprofile" ng-model="user.profile">
    <option ng-repeat="profile in userprofiles" value="{{profile.profile}}">
        {{ profile.profile_name }}
    </option>
</select>

Controller.js代码:

$scope.selectedAll = function(){
    $scope.user.profile = []; 
    angular.forEach($scope.userprofiles, function(item){
       $scope.user.profile.push( item.profile);
    }); 
}

1 个答案:

答案 0 :(得分:0)

需要设置$ scope.user.profile [item] = true;

$scope.selectedAll = function(){
$scope.user.profile = []; 
angular.forEach($scope.userprofiles, function(item){
    $scope.user.profile.push( item.profile.toString());
    $scope.user.profile[item] = true;
}); 
}