diff --git a/src/base/combination/group.virtual.js b/src/base/combination/group.virtual.js index eb2b63b85..299cb5d8a 100644 --- a/src/base/combination/group.virtual.js +++ b/src/base/combination/group.virtual.js @@ -66,11 +66,11 @@ BI.VirtualGroup = BI.inherit(BI.Widget, { }, addItems: function (items) { - this.layouts.addItems(items); + this.layouts.addItems(items, this); }, prependItems: function (items) { - this.layouts.prependItems(items); + this.layouts.prependItems(items, this); }, setValue: function (v) { diff --git a/src/base/list/virtualgrouplist.js b/src/base/list/virtualgrouplist.js index 7a4a9323b..9039552c2 100644 --- a/src/base/list/virtualgrouplist.js +++ b/src/base/list/virtualgrouplist.js @@ -21,7 +21,6 @@ BI.VirtualGroupList = BI.inherit(BI.Widget, { }, init: function () { - var self = this; this.renderedIndex = -1; }, @@ -90,10 +89,10 @@ BI.VirtualGroupList = BI.inherit(BI.Widget, { var getElementHeight = function () { return self.container.element.height() + self.topBlank.element.height() + self.bottomBlank.element.height(); }; - while ((lastHeight = getElementHeight()) < minContentHeight && index < o.items.length) { + while ((lastHeight = this.renderedIndex === -1 ? 0 : getElementHeight()) < minContentHeight && index < o.items.length) { var items = o.items.slice(index, index + o.blockSize); - this.container.addItems(items.map(function (item, i) { - return o.itemFormatter(item, index + i) + this.container[self.renderedIndex === -1 ? "populate" : "addItems"](items.map(function (item, i) { + return o.itemFormatter(item, index + i); }), this); var addedHeight = getElementHeight() - lastHeight; this.tree.set(cnt, addedHeight); @@ -142,7 +141,9 @@ BI.VirtualGroupList = BI.inherit(BI.Widget, { _populate: function (items) { var o = this.options; if (items && this.options.items !== items) { + // 重新populate一组items,需要重新对线段树分块 this.options.items = items; + this._restore(); } this.tree = BI.PrefixIntervalTree.uniform(Math.ceil(o.items.length / o.blockSize), this._isAutoHeight() ? 0 : o.rowHeight * o.blockSize); @@ -153,14 +154,18 @@ BI.VirtualGroupList = BI.inherit(BI.Widget, { } }, - restore: function () { + _restore: function () { this.renderedIndex = -1; - this.options.scrollTop = 0; // 依赖于cache的占位元素也要初始化 this.topBlank.setHeight(0); this.bottomBlank.setHeight(0); }, + restore: function () { + this.options.scrollTop = 0; + this._restore(); + }, + populate: function (items) { this._populate(items); }