2015-09-14 72 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

相關問題