寻找带有AngularJS和Bootstrap的双重列表框 [英] Looking for a Dual Listbox with AngularJS and Bootstrap

查看:42
本文介绍了寻找带有AngularJS和Bootstrap的双重列表框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找这样一个包含在我的项目中的组件:

I am looking for a component like this to be included in my project:

http://geodan.github.io/duallistbox/sample-100.html

我想用npm安装它.

问题是我测试了那里的一些示例,但是没有成功(我得到了例外,或者没有npm,只有凉亭)

The problem is that I tested some of the examples which are over there, but without success (I get exceptions, or there is no npm, only bower)

这些是我测试过的示例.

These are the examples I tested.

  • https://github.com/alexklibisz/angular-dual-multiselect-directive
  • https://github.com/frapontillo/angular-bootstrap-duallistbox
  • http://www.bootply.com/mRcBel7RWm

关于使用AngularJs,Bootstrap和npm的任何建议吗?

Any recommendations about one with AngularJs, Bootstrap, and npm?

推荐答案

这可能会解决您的要求:双重列表框

This might solve your requirement: Dual list Box

angular.module('plunker', [])
  .controller('MainCtrl', function($scope, utils) {
    $scope.list1 = [],
      $scope.list2 = [];

    utils.insertData($scope.list1, 5);

  })
  .factory('utils', function Utils() {
    return {
      insertData: function(list, numItems) {
        for (var i = 0; i < numItems; i++) {
          list.push({
            id: i + 1,
            title: 'item' + (i + 1)
          });
        }
      },
      getIndexesFromList: function(list) {
        var newList = [];
        for (var i in list) {
          if (typeof list[i].id === "number" && newList.indexOf(list[i].id) === -1) newList.push(list[i].id)
        }
        return newList;
      },
      getAllSelectedItems: function(list) {
        var newList = [];
        newList = list.filter(function(el) {
          return el.active === true;
        });
        return newList;
      },
      addListIfNoExists: function(list2, newListToAppend) {
        var indexes = this.getIndexesFromList(list2);
        var newList = [];
        for (var i in newListToAppend) {
          if (indexes.indexOf(newListToAppend[i].id) === -1) list2.push(newListToAppend[i])
        }
        return list2;
      }
    }
  })
  .directive('dualList', function(utils) {

    function _controller($scope) {
      $scope.selectAllItem = function(list, checked) {
        list.map(function(item) {
          item.active = checked
          return item;
        });
      };
      $scope.getAllSelectedItems = function(list) {
        return utils.getAllSelectedItems(list);
      }
      $scope.moveItemToRightList = function() {
        var newListToAppend = $scope.list1.filter(function(el) {
          if (el.active === true) {
            el.active = false;
            return el;
          }
        });
        if (newListToAppend.length > 0) {
          $scope.list1 = $scope.list1.filter(function(el) {
            return utils.getIndexesFromList(newListToAppend).indexOf(el.id) === -1;
          });
          $scope.list2 = utils.addListIfNoExists($scope.list2, newListToAppend);
          if ($scope.list1.length === 0) $scope.checked1 = false;
        }

      };
      $scope.moveItemToLeftList = function() {
        var newListToAppend = $scope.list2.filter(function(el) {
          if (el.active === true) {
            el.active = false;
            return el;
          }
        });
        if (newListToAppend.length > 0) {
          $scope.list2 = $scope.list2.filter(function(el) {
            return utils.getIndexesFromList(newListToAppend).indexOf(parseInt(el.id)) === -1;
          });
          $scope.list1 = utils.addListIfNoExists($scope.list1, newListToAppend);
          if ($scope.list2.length === 0) $scope.checked2 = false;
        }

      };
    }
    return {
      restrict: "E",
      scope: true,
      controller: _controller,
      templateUrl: "dualList.html"
    };
  });

dualList.html

<div class="container">
  <br />
  <div class="row">
    <div class="dual-list list-left col-md-5">
      <div class="well text-right">
        <div class="row">
          <div class="col-md-3">
            <div class="checkbox">
              <label>
                <input type="checkbox"
                       ng-model="checked1"
                       ng-click="selectAllItem(list1, checked1)">
                    Todo {{getAllSelectedItems(list1).length}}/{{list1.length}}
              </label>
            </div>
          </div>
          <div class="col-md-9">
            <div class="input-group">
              <span class="input-group-addon glyphicon glyphicon-search"></span>
              <input type="text"
                     name="SearchDualList"
                     ng-model="search1"
                     class="form-control"
                     placeholder="search" />
            </div>
          </div>
        </div>
        <ul class="list-group">
          <a class="list-group-item"
             href=""
             data-id="{{item.id}}"
             ng-click="item.active = !item.active"
             ng-class="{active: item.active}"
             ng-repeat="item in list1|filter: search1">{{item.title}}</a>
        </ul>
        <p ng-if="(list1 | filter:search1).length == 0">Sin Datos</p>
      </div>
    </div>
    <div class="list-arrows col-md-1 text-center">
      <button ng-click="moveItemToLeftList()"
              class="btn btn-default btn-sm move-left">
        <span class="glyphicon glyphicon-chevron-left"></span>
      </button>
      <button ng-click="moveItemToRightList()"
              class="btn btn-default btn-sm move-right">
        <span class="glyphicon glyphicon-chevron-right"></span>
      </button>
    </div>
    <div class="dual-list list-right col-md-5">
      <div class="well">
        <div class="row">
          <div class="col-md-3">
            <div class="checkbox">
              <label>
                <input type="checkbox"
                       ng-model="checked2"
                       ng-click="selectAllItem(list2, checked2)">
                    Todo {{getAllSelectedItems(list2).length}}/{{list2.length}}
              </label>
            </div>
          </div>
          <div class="col-md-9">
            <div class="input-group">
              <span class="input-group-addon glyphicon glyphicon-search"></span>
              <input type="text"
                     name="SearchDualList"
                     ng-model="search2"
                     class="form-control"
                     placeholder="search" />
            </div>
          </div>
        </div>
        <ul class="list-group">
          <a class="list-group-item"
             href=""
             data-id="{{item.id}}"
             ng-click="item.active = !item.active"
             ng-class="{active: item.active}"
             ng-repeat="item in list2|filter: search2">{{item.title}}</a>
        </ul>
        <p ng-if="(list2 | filter:search2).length == 0">Sin Datos</p>
      </div>
    </div>
  </div>
</div>

index.html

<!DOCTYPE html>
<html ng-app="plunker">
  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <script data-require="jquery@*" data-semver="2.1.4" src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
    <script src="https://code.angularjs.org/1.3.0/angular.js"></script>
    <link data-require="bootstrap@*" data-semver="3.3.5" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
    <link data-require="bootstrap@*" data-semver="3.3.5" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.css" />
    <link data-require="font-awesome@*" data-semver="4.3.0" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" />
    <script>
      document.write('<base href="' + document.location + '" />');
    </script>
    <link rel="stylesheet" href="style.css" />
    <script src="app.js"></script>
  </head>
  <body ng-controller="MainCtrl">
    <dual-list data-list1="list1" data-list2="list2"></dual-list>
  </body>
</html>

style.css

.dual-list .list-group {
    margin-top: 8px;
}
.list-arrows {
    padding-top: 100px;
}
.list-arrows button {
    margin-bottom: 20px;
}
.list-group-item.active, .list-group-item.active:hover, .list-group-item.active:focus {
  border-color: white;
}
.input-group-addon {
  top: 0;
}

这篇关于寻找带有AngularJS和Bootstrap的双重列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆