2015-09-14 88 views
2

我正在使用ng-sortable来重新排列列表元素的功能。 在这我打算申请NG-对列表进行排序是:TypeError:无法读取未定义的属性'0' - ng-Sortable(AngularJs)

List B : [object Object],[object Object],[object Object]

Example

以下是我的代码:

HTML -

<div data-as-sortable-item-handle> 
    <!-- <div class="list-group-item"> --> 
     {{$index + 1}}{{user.Name}} <input ng-click="ctrl.selectB(user.id)" name="ctrl.selectedB[]" value="{{user.id}}" ng-checked="ctrl.selectedB.indexOf(user.id) > -1" 
           type="checkbox" class="pull-right"> 
<!-- </div> --> 
</div> 

</li> 
</ul> 

控制器 -

$scope.dragControlListeners = { 
         accept: function (sourceItemHandleScope, destSortableScope) 
         {return sourceItemHandleScope.itemScope.sortableScope.$id === destSortableScope.$id;}, 
         itemMoved: function (event) { 
          //Do what you want }, 
         }, 
         orderChanged: function(event) { 
          //Do what you want}, 
         } 
             }; 

但我得到的错误:

TypeError: Cannot read property '0' of undefined

TypeError: Cannot read property '1' of undefined

,当我尝试拖动的元素,所有元素都被视为一个单独的单元,并拖累,在行动上,我想每个L1元素indivually行动并可拖动。

收到错误 -

Uncaught TypeError: Cannot read property 'splice' of undefined

回答

6

你有更多的代码来告诉我们?今天有相同的错误信息,并通过将ng-model设置为与ng-repeat相同的列表来解决它。

<div as-sortable="dragControlListeners" ng-model="foo"> 
 
    <div ng-repeat="bar in foo"> 
 
    <div as-sortable-item class="as-sortable-item"> 
 
     Lorum ipsum 
 
     <div as-sortable-item-handle class="as-sortable-item-handle">Drag</div> 
 
    </div> 
 
    </div> 
 
</div>

+0

好吧!将尝试 – Learner

+0

但我发现执行此拖放操作的另一个更好和更好的库是angular-dndlists(https://github.com/marceljuenemann/angular-drag-and-drop-lists)。 试试吧! – Learner

相关问题