0

Consider the following function . This will be called everytime the browser is resized and every time I want to pass the same initial value of the this.original_ul to this function doLayout() . It is computed only once inside an initialization function separately . Right now what is happening is second time when it is called , the changes to the $ul variable also is getting reflected on this.original_ul . How can I possibly prevent this ?

doLayout : function () {
    alert('doLayout');
    var size, $ul, $lis, loop, i;
    size = this.computeElesPerCol();
    $ul = this.original_ul; // I wanna  preserve this between calls
    $lis = $ul.children().filter(':gt(' + (size - 1) + ')');
    loop = Math.ceil($lis.length / size);
    i = 0;

    $ul.css('float', 'left').wrap("<div style='overflow: hidden'></div>");

    for (; i < loop; i = i + 1) {
      $ul = $("<ul />").css('float', 'left').append($lis.slice(i * size, (i * size) + 4)).insertAfter($ul);
      $ul.css("list-style","none");
    }
  }

Edit: : this is a reference to the javascript object WebFloatLayout which basically does a multi column layout depending on the available height every time the browser is resized . The initial input is a long list of <lis> in a single <ul> . Here is how it gets initialized :

     initialize:function () {
    var webFloatLayout = this;
    //call super parent initialize which will set the main dom element of component
    ec.comp.Component.prototype.initialize.call(this);
    var innerDivId = this.id + "_inner";
    innerDivId = innerDivId.replace(new RegExp(ec.config.separator, "g"), "\\" + ec.config.separator);
    $(document).ready(function() {
      webFloatLayout.original_ul = $("#" + innerDivId).find(">:first-child");
      webFloatLayout.original_ul.css("list-style","none");
      webFloatLayout.layout();
    });
  },
4

1 に答える 1

2

Try the clone method:

$ul = this.original_ul.clone();
于 2012-07-27T12:19:21.850 に答える