【问题标题】:TypeError: Cannot read property '0' of undefined -- ng-Sortable ( AngularJs )TypeError:无法读取未定义的属性“0”——ng-Sortable(AngularJs)
【发布时间】:2015-09-14 05:38:30
【问题描述】:

我使用ng-sortable 来重新排序列表元素。 我打算应用 ng-sortable 的列表是:

列表 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: 无法读取未定义的属性“0”

TypeError:无法读取未定义的属性“1”

当我尝试拖动元素时,所有元素都被视为一个单独的单元并被拖动,实际上我希望每个 li 元素单独行动并且可以拖动。

出现错误 -

未捕获的类型错误:无法读取未定义的属性“拼接”

【问题讨论】:

    标签: angularjs ng-sortable


    【解决方案1】:

    你有更多的代码给我们看吗?今天有同样的错误信息,并通过将 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>

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-26
    相关资源
    最近更新 更多