如何使用drop-model事件访问拖放的确切模型项?
从文档中删除事件的说明:
el was dropped into target before a sibling element,and originally came from source
el似乎返回被拖动的HTML元素,但是我需要对它后面的实际数据项执行操作.任何提示?
<div class="collapse" id="manageUsers"> <div class='containerDragula' dragula='"bag"' dragula-model='usersInProject'> <div ng-repeat='user in usersInProject' ng-bind='user.email'></div> </div> <div class='containerDragula' dragula='"bag"' dragula-model='usersNotInProject'> <div ng-repeat='user in usersNotInProject' ng-bind='user.email'></div> </div> </div> $scope.$on('bag.drop-model',function (e,el,target,source) { //this returns the html element console.log(el); });
我有同样的问题,并通过将项目的id添加到HTML元素来解决它.
原文链接:https://www.f2er.com/angularjs/142841.html这样的事情
<div id="{{ user.id }}" ng-repeat='user in usersNotInProject' ng-bind='user.email'></div>
在控制器中,我使用id查找项目:
$scope.$on('bag.drop-model',source) { //getById is a function you implement (unless you already have it) console.log(usersNotInProject.getById(el.attr('id')).email); });