简体   繁体   English

角度-未选择编辑角色

[英]Angular - On edit roles does not selected

There is User Roles. 有用户角色。 $scope.allRoles and i assign multiple roles to user user.roles . $scope.allRoles和我为用户user.roles分配了多个角色。

       <label class="col-md-4" >Roles</label>
       <div class="col-md-8">
            <select multiple="true" ng-model="user.roles" ng-options="r.name for r in allRoles"></select>
       <div>

But When i Edit the User - The Pre-Assigned Roles should be highlighted but it does not. 但是,当我编辑用户时-应突出显示“预分配角色”,但不要突出显示。

The Roles in MultiSelect Dropdown Should be highlighted. MultiSelect下拉菜单中的角色应突出显示。 Can anyone guide me. 谁能指导我。 Thanks Image of the MultiSelect Here 感谢这里的MultiSelect图片

This link will may help you http://jsfiddle.net/jaredwilli/vUSPu/ 该链接可能会对您有所帮助http://jsfiddle.net/jaredwilli/vUSPu/

<div ng-app="myApp" ng-controller="AppCtrl">    
<dropdown-multiselect pre-selected="member.roles" model="selected_items" options="roles"></dropdown-multiselect>


<pre>selected roles = {{selected_items | json}}</pre>

and in app.js 并在app.js中

'use strict';

var app = angular.module('myApp', ['app.directives']);

app.controller('AppCtrl', function($scope){                     
    $scope.roles = [
          {"id": 1, "name": "Manager", "assignable": true},
          {"id": 2, "name": "Developer", "assignable": true},
          {"id": 3, "name": "Reporter", "assignable": true}
    ];

    $scope.member = {roles: []};
    $scope.selected_items = [1,3];
});

var app_directives = angular.module('app.directives', []);

app_directives.directive('dropdownMultiselect', function(){
   return {
       restrict: 'E',
       scope:{           
            model: '=',
            options: '=',
            pre_selected: '=preSelected'
       },
       template: "<div class='btn-group' data-ng-class='{open: open}'>"+
        "<button class='btn btn-small'>Select</button>"+
                "<button class='btn btn-small dropdown-toggle' data-ng-click='open=!open;openDropdown()'><span class='caret'></span></button>"+
                "<ul class='dropdown-menu' aria-labelledby='dropdownMenu'>" + 
                    "<li><a data-ng-click='selectAll()'><i class='icon-ok-sign'></i>  Check All</a></li>" +
                    "<li><a data-ng-click='deselectAll();'><i class='icon-remove-sign'></i>  Uncheck All</a></li>" +                    
                    "<li class='divider'></li>" +
                    "<li data-ng-repeat='option in options'> <a data-ng-click='setSelectedItem()'>{{option.name}}<span data-ng-class='isChecked(option.id)'></span></a></li>" +                                        
                "</ul>" +
            "</div>" ,
       controller: function($scope){

           $scope.openDropdown = function(){        
                    $scope.selected_items = [];
                    for(var i=0; i<$scope.pre_selected.length; i++){                        $scope.selected_items.push($scope.pre_selected[i].id);
                    }                                        
            };

            $scope.selectAll = function () {
                $scope.model = _.pluck($scope.options, 'id');
                console.log($scope.model);
            };            
            $scope.deselectAll = function() {
                $scope.model=[];
                console.log($scope.model);
            };
            $scope.setSelectedItem = function(){
                var id = this.option.id;
                if (_.contains($scope.model, id)) {
                    $scope.model = _.without($scope.model, id);
                } else {
                    $scope.model.push(id);
                }
                console.log($scope.model);
                return false;
            };
            $scope.isChecked = function (id) {                 
                if (_.contains($scope.model, id)) {
                    return 'icon-ok pull-right';
                }
                return false;
            };                                 
       }
   } 
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何过滤编辑的数据,它应该在 angular 中显示选择编辑的数据 - How to filter the data that edit and it should display the data that selected to edit in angular 在angular6中为“编辑”表单预先选择的选项(“下拉”) - pre-selected option ( Dropdown ) for Edit form in angular6 如何在 angular 的编辑表单中填充单选按钮选定的值 - how to populate radio button selected value in edit form in angular JQuery 单击编辑帖子和选定的 id 不起作用 - JQuery click edit post and selected id does not work 以角度选择选项时,下拉列表不会折叠 - Dropdown does not collapse when the option is selected in angular Angular AuthorizeGuard 角色 - Angular AuthorizeGuard Roles 反应钩子编辑表单没有 select 记录要编辑。currentId 正确但选择的记录未定义 - react hooks edit form does not select record to edit .the currentId is correct but record selected is undefined 无法使用 discord.js 编辑角色 - Cannot edit roles with discord.js Angular JWT 有少量角色访问 - Angular JWT with few Roles acess 在编辑行时,取消按钮将如何工作?如果我想一次在AngularJS中使用编辑按钮来编辑所选项目? - While editing a row , How does the cancel button will work and If I want to edit selected items at a time with edit button in AngularJS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM