From 7f597035fbdac03f23c08e988ca0eec10362c294 Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Mon, 28 Mar 2022 18:22:26 +0800 Subject: [PATCH] =?UTF-8?q?BI-102470=20virtualgrouplist=E7=9A=84rowHeight?= =?UTF-8?q?=E4=B8=BAauto=E6=97=B6populate=E5=88=B7=E6=96=B0=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/base/combination/group.virtual.js | 4 ++-- src/base/list/virtualgrouplist.js | 17 +++++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) 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); }