如何使用AngularJs和Angular拖放来获取放置元素的目标ID?

时间:2018-10-25 20:59:11

标签: angularjs drag-and-drop

我正在使用Angular Dnd ,并且尝试获取已删除元素的目标索引,所以假设我将元素编号1拖到第11位-那么我希望能够得到它...

我已经做了一些我没有做过的测试,但是似乎没有任何作用...

    <div ng-controller="MyCtrl">
      <ul dnd-list="users" class="list-group" dnd-drop="logEvent(event)">
        <li ng-repeat="user in users" class="list-group-item" dnd-draggable="user" dnd-moved="users.splice($index, 1)" dnd-effect-allowed="move" dnd-dragover="logEvent(event)">
          {{myVar}}
          <div class="inline-text">
            <span>:::</span> {{user.name}}
          </div>
        </li>
      </ul>
    </div>


angular.module('App', ['dndLists'])
      .controller('MyCtrl', ['$scope', function($scope) {

        $scope.logEvent = function(event) {

        console.log(event.target)

        }

        $scope.users = [{
            'id': 4,
            'name': 'too',

          },
          {
            'id': 2,
            'name': 'goo',
          },
          {
            'id': 3,
            'name': 'roo',
          },
          {
            'id': 1,
            'name': 'foo',
          },
          {
            'id': 5,
            'name': 'eoo',
          },

        ];


      }])

Fiddle

0 个答案:

没有答案