From 773885f24bf71924c5916ca75070d6c26c466500 Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Tue, 22 Feb 2022 10:37:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A0JIRA=E4=BB=BB=E5=8A=A1=20virtualgroup?= =?UTF-8?q?=20items=E7=9A=84context=E4=B8=A2=E5=A4=B1=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/core/wrapper/layout.js | 32 ++++++++++++++++----------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/base/combination/group.virtual.js b/src/base/combination/group.virtual.js index ed21ba209..ab9b20c07 100644 --- a/src/base/combination/group.virtual.js +++ b/src/base/combination/group.virtual.js @@ -109,7 +109,9 @@ BI.VirtualGroup = BI.inherit(BI.Widget, { if (!this.layouts) { this.layouts = BI.createWidget(BI.extend({element: this}, this._packageLayout(items))); } else { - this.layouts.populate(items); + this.layouts.populate(items, { + context: this + }); } } }); diff --git a/src/core/wrapper/layout.js b/src/core/wrapper/layout.js index 4c94198ff..f4f32cfdd 100644 --- a/src/core/wrapper/layout.js +++ b/src/core/wrapper/layout.js @@ -492,7 +492,7 @@ BI.Layout = BI.inherit(BI.Widget, { } }, - updateChildren: function (oldCh, newCh) { + updateChildren: function (oldCh, newCh, context) { var self = this; var oldStartIdx = 0, newStartIdx = 0; var oldEndIdx = oldCh.length - 1; @@ -546,7 +546,7 @@ BI.Layout = BI.inherit(BI.Widget, { } else { var sameOldVnode = findOldVnode(oldCh, newStartVnode, oldStartIdx, oldEndIdx); if (BI.isNull(sameOldVnode[0])) { // 不存在就把新的放到左边 - var node = addNode(newStartVnode, newStartIdx); + var node = addNode(newStartVnode, newStartIdx, context); insertBefore(node, oldStartVnode); } else { // 如果新节点在旧节点区间中存在就复用一下 var sameOldIndex = sameOldVnode[1]; @@ -561,7 +561,7 @@ BI.Layout = BI.inherit(BI.Widget, { } if (oldStartIdx > oldEndIdx) { before = BI.isNull(newCh[newEndIdx + 1]) ? null : newCh[newEndIdx + 1]; - addVnodes(before, newCh, newStartIdx, newEndIdx); + addVnodes(before, newCh, newStartIdx, newEndIdx, context); } else if (newStartIdx > newEndIdx) { removeVnodes(oldCh, oldStartIdx, oldEndIdx); } @@ -586,15 +586,15 @@ BI.Layout = BI.inherit(BI.Widget, { } } - function addNode (vnode, index) { + function addNode (vnode, index, context) { var opt = self._getOptions(vnode); var key = opt.key == null ? index : opt.key; - return children[key] = self._newElement(index, vnode); + return children[key] = self._newElement(index, vnode, context); } - function addVnodes (before, vnodes, startIdx, endIdx) { + function addVnodes (before, vnodes, startIdx, endIdx, context) { for (; startIdx <= endIdx; ++startIdx) { - var node = addNode(vnodes[startIdx], startIdx); + var node = addNode(vnodes[startIdx], startIdx, context); insertBefore(node, before, false, startIdx); } } @@ -662,16 +662,18 @@ BI.Layout = BI.inherit(BI.Widget, { update: function (opt) { var o = this.options; var items = opt.items || []; + var context = opt.context; var oldItems = o.items; this.options.items = items; - return this.updateChildren(oldItems, items); + return this.updateChildren(oldItems, items, context); }, - stroke: function (items) { + stroke: function (items, options) { + options = options || {}; var self = this; BI.each(items, function (i, item) { if (item) { - self._addElement(i, item); + self._addElement(i, item, options.context); } }); }, @@ -702,14 +704,18 @@ BI.Layout = BI.inherit(BI.Widget, { this.options.items = []; }, - populate: function (items) { + populate: function (items, options) { items = items || []; + options = options || {}; if (this._isMounted) { - this.update({items: items}); + this.update({ + items: items, + context: options.context + }); return; } this.options.items = items; - this.stroke(items); + this.stroke(items, options); }, resize: function () {