使用AngularJs刷新多个列表框

时间:2014-08-25 05:52:42

标签: angularjs listbox coffeescript

我有2个多个列表框,如下所示

enter image description here

当我从左侧列表框中选择多个值并单击右箭头时,它会将这些值移动到右侧列表框中,这些值将从左侧列表框中删除。

HTML

    <select multiple ng-model="selectedRoleValue">
        <option ng-selected="selectrole" ng-repeat="role in roles | filter:searchRoleOne" value="{{role}}">{{role}}</option>
    </select>
    <img src="./images/arrow.svg" ng-click="addToRightPan()">
    <select name="cars" multiple class="listMutiple top5" ng-model="removeRoleValue">                                
        <option ng-selected="selectrrole" ng-repeat="role in newRoleValue | filter:searchRoleTwo" value="{{role}}">{{role}}</option>
    </select>

coffeescript代码

    $scope.roles = ["test role","test role1","test role2","test role3","test role4","test role5"]

    $scope.addToRightPan = ()->   
        $scope.temprole = $scope.roles
        for item in $scope.selectedRoleValue
            $scope.newRoleValue.push item
            t = $scope.temprole.filter (word) -> word isnt item
            $scope.temprole = t
        $scope.roles = $scope.temprole
        return

addToRightPan()是将值从左侧列表框移动到右侧列表框的功能。

功能正常。但是,当我只选择左侧列表框中的值并移动到右侧列表框时,左侧列表框中会显示一个空行。但是,当我安慰价值时,我找不到任何空值或任何东西。

在inspect元素中,我发现了以下内容:

  <option value="? string:Account Cordinator ?"></option>

enter image description here

我该如何删除它?或者是否可以明确刷新列表框?

1 个答案:

答案 0 :(得分:1)

我得到了它的工作,

<select multiple ng-selected="selectrole" ng-model="selectedRoleValue" ng-options="role for role in roles | filter:searchRoleOne">
</select>

我将ng-repeat更改为ng-options