如何重置Packery实例并重新初始化



如何重置包装厂?

如果我使用packery('destroy'),它会重置结构,但在重新初始化时丢失了顺序实例,它总是给出相同的索引号。。。。

我厌倦了重新初始化整个元素,但双重绑定使生活更加困难。

var $slidesElem = $('ul.ordering-tool-list'),
             slidesHeight = $slidesElem.find('li').outerHeight(),
             slidesWidth = $slidesElem.find('li').outerWidth();
             if(typeof $scope.pckry !=='undefined'){
                 $scope.initAside.onlyDestroy();
             }
        //Packery Call
        this.initialize =function(execute){
             $scope.pckry = $slidesElem.packery({
                            'itemSelector':".handleMe",
                            'rowHeight': slidesHeight,
                            'columnWidth': slidesWidth
                        });
            var itemElems = $scope.pckry.packery('getItemElements');
            $scope.initialItem = itemElems;
            for ( var i=0, len = itemElems.length; i < len; i++ ) {
                // make element draggable with Draggabilly
                var draggie = new Draggabilly( itemElems[i],{
                    axis: 'y',
                    containment:$slidesElem,
                    grid: [ 0, 24 ]
                });
                // bind Draggabilly events to Packery
                $scope.pckry.packery('bindDraggabillyEvents', draggie);
              }
            $scope.pckry.packery('on', 'dragItemPositioned',this.orderItems);
            $scope.pckry.packery('on', 'layoutComplete', this.orderItems );
        }
       //Set the orderof Items
        this.orderItems = function() {
            var $itemElems = $scope.pckry.packery('getItemElements');
             for (var i=0; i< $itemElems.length; i++) {
                var indexToPut = $($itemElems[i]).attr("tabindex");
              $scope.itemPositioned[i] = indexToPut;
              $scope.profileContent[indexToPut].id = i;
              $($itemElems[i]).attr('data-module-index', i);
            }
            $scope.$apply();
        };
        //reset The Order
        this.resetOrder = function(){
             var $itemElems = $scope.initialItem;
             for (var i=0; i< $itemElems.length; i++) {
              $scope.itemPositioned[i] = $($itemElems[i]).attr("tabindex");
              $($itemElems[i]).attr('data-module-index', i); 
              $scope.profileContent[i].id = i;
            }
        };
        //Destroy Event for reset
        this.destroy = function(){
            //$scope.pckry.packery('destroy');
            //$scope.pckry.packery();
            //$scope.pckry = null;
            //this.initialize(false);
            this.resetOrder();
            //this.initialize(false);
        };

找到使用"reload"的解决方案

$scope.pckry.packery('reloadItems');

相关内容

  • 没有找到相关文章

最新更新