考虑以下功能。每次调整浏览器大小时都会调用此方法,并且每次我想将this.original_ul
的相同初始值传递给此函数doLayout()
时。它仅在初始化函数内分别计算一次。现在正在发生的事情是第二次调用它时,对$ul
变量的更改也会反映在this.original_ul
上。我怎么可能阻止这个?
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");
}
}
编辑:this
是对javascript对象WebFloatLayout的引用,它基本上根据每次调整浏览器时的可用高度执行多列布局。初始输入是单个<lis>
中的<ul>
的长列表。以下是初始化的方法:
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();
});
},