programing

Angular가 있는 듀얼 목록 상자 찾기JS 및 부트스트랩

css3 2023. 3. 21. 22:24

Angular가 있는 듀얼 목록 상자 찾기JS 및 부트스트랩

제 프로젝트에 포함할 다음과 같은 컴포넌트를 찾고 있습니다.

여기에 이미지 설명 입력

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

npm과 함께 설치하고 싶습니다.

문제는 여기에 있는 몇 가지 예를 테스트했지만 성공하지 못했다는 것입니다(예외가 발생하거나 npm이 없고 bower만 있습니다).

이것들은 제가 테스트한 예들입니다.

AngularJs, Bootstrap 및 npm을 사용하는 것에 대해 추천할 만한 것이 있습니까?

이것으로 요건을 해결할 수 있습니다.듀얼 리스트 박스

app.module

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.displaces를 표시합니다.

<!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;
}

이 링크가 도움이 될 것 같아요.

npm https://www.npmjs.com/package/ng2-dual-list-box에서 설치하면 각도가 2/4인 경우 이 npm을 사용해 주세요.

언급URL : https://stackoverflow.com/questions/38101913/looking-for-a-dual-listbox-with-angularjs-and-bootstrap