Browse Source

Pull request #2231: 无JIRA任务 bugfix

Merge in VISUAL/fineui from ~GUY/fineui:master to master

* commit 'a5b8c254f3f930fddff8162248a7fcdbf7034619':
  bugfix
es6
guy 3 years ago
parent
commit
dc9740e9be
  1. 32
      src/core/wrapper/layout.js

32
src/core/wrapper/layout.js

@ -237,9 +237,9 @@ BI.Layout = BI.inherit(BI.Widget, {
// 不依赖于this.options.items进行更新 // 不依赖于this.options.items进行更新
_updateItemAt: function (oldIndex, newIndex, item) { _updateItemAt: function (oldIndex, newIndex, item) {
var del = this._children[this._getChildName(oldIndex)]; var del = this._children[this._getChildName(oldIndex)];
delete this._children[this._getChildName(oldIndex)]; var w = this._newElement(newIndex, item);
var w = this._addElement(newIndex, item); // 需要有个地方临时存一下新建的组件,否则如果直接使用newIndex的话,newIndex位置的元素可能会被用到
this._children[this._getChildName(newIndex)] = w; this._children[this._getChildName(newIndex) + "-temp"] = w;
if (oldIndex > 0) { if (oldIndex > 0) {
this._children[this._getChildName(oldIndex - 1)].element.after(w.element); this._children[this._getChildName(oldIndex - 1)].element.after(w.element);
} else { } else {
@ -247,6 +247,7 @@ BI.Layout = BI.inherit(BI.Widget, {
} }
del._destroy(); del._destroy();
w._mount(); w._mount();
return true;
}, },
_addItemAt: function (index, item) { _addItemAt: function (index, item) {
@ -453,24 +454,28 @@ BI.Layout = BI.inherit(BI.Widget, {
} else if (BI.isNull(oldEndVnode)) { } else if (BI.isNull(oldEndVnode)) {
oldEndVnode = oldCh[--oldEndIdx]; oldEndVnode = oldCh[--oldEndIdx];
} else if (sameVnode(oldStartVnode, newStartVnode, oldStartIdx, newStartIdx)) { } else if (sameVnode(oldStartVnode, newStartVnode, oldStartIdx, newStartIdx)) {
updated = this.patchItem(oldStartVnode, newStartVnode, oldStartIdx, newStartIdx) || updated; var willUpdate = this.patchItem(oldStartVnode, newStartVnode, oldStartIdx, newStartIdx);
children[oldStartVnode.key == null ? oldStartIdx : oldStartVnode.key] = this._children[this._getChildName(oldStartIdx)]; updated = willUpdate || updated;
children[oldStartVnode.key == null ? oldStartIdx : oldStartVnode.key] = willUpdate ? this._children[this._getChildName(newStartIdx) + "-temp"] : this._children[this._getChildName(oldStartIdx)];
oldStartVnode = oldCh[++oldStartIdx]; oldStartVnode = oldCh[++oldStartIdx];
newStartVnode = newCh[++newStartIdx]; newStartVnode = newCh[++newStartIdx];
} else if (sameVnode(oldEndVnode, newEndVnode, oldEndIdx, newEndIdx)) { } else if (sameVnode(oldEndVnode, newEndVnode, oldEndIdx, newEndIdx)) {
updated = this.patchItem(oldEndVnode, newEndVnode, oldEndIdx, newEndIdx) || updated; var willUpdate = this.patchItem(oldEndVnode, newEndVnode, oldEndIdx, newEndIdx);
children[oldEndVnode.key == null ? oldEndIdx : oldEndVnode.key] = this._children[this._getChildName(oldEndIdx)]; updated = willUpdate || updated;
children[oldEndVnode.key == null ? oldEndIdx : oldEndVnode.key] = willUpdate ? this._children[this._getChildName(newEndIdx) + "-temp"] : this._children[this._getChildName(oldEndIdx)];
oldEndVnode = oldCh[--oldEndIdx]; oldEndVnode = oldCh[--oldEndIdx];
newEndVnode = newCh[--newEndIdx]; newEndVnode = newCh[--newEndIdx];
} else if (sameVnode(oldStartVnode, newEndVnode)) { } else if (sameVnode(oldStartVnode, newEndVnode)) {
updated = this.patchItem(oldStartVnode, newEndVnode, oldStartIdx, newStartIdx) || updated; var willUpdate = this.patchItem(oldStartVnode, newEndVnode, oldStartIdx, newStartIdx);
children[oldStartVnode.key == null ? oldStartIdx : oldStartVnode.key] = this._children[this._getChildName(oldStartIdx)]; updated = willUpdate || updated;
children[oldStartVnode.key == null ? oldStartIdx : oldStartVnode.key] = willUpdate ? this._children[this._getChildName(newStartIdx) + "-temp"] : this._children[this._getChildName(oldStartIdx)];
insertBefore(oldStartVnode, oldEndVnode, true); insertBefore(oldStartVnode, oldEndVnode, true);
oldStartVnode = oldCh[++oldStartIdx]; oldStartVnode = oldCh[++oldStartIdx];
newEndVnode = newCh[--newEndIdx]; newEndVnode = newCh[--newEndIdx];
} else if (sameVnode(oldEndVnode, newStartVnode)) { } else if (sameVnode(oldEndVnode, newStartVnode)) {
updated = this.patchItem(oldEndVnode, newStartVnode, oldEndIdx, newEndIdx) || updated; var willUpdate = this.patchItem(oldEndVnode, newStartVnode, oldEndIdx, newEndIdx);
children[oldEndVnode.key == null ? oldEndIdx : oldEndVnode.key] = this._children[this._getChildName(oldEndIdx)]; updated = willUpdate || updated;
children[oldEndVnode.key == null ? oldEndIdx : oldEndVnode.key] = willUpdate ? this._children[this._getChildName(newEndIdx) + "-temp"] : this._children[this._getChildName(oldEndIdx)];
insertBefore(oldEndVnode, oldStartVnode); insertBefore(oldEndVnode, oldStartVnode);
oldEndVnode = oldCh[--oldEndIdx]; oldEndVnode = oldCh[--oldEndIdx];
newStartVnode = newCh[++newStartIdx]; newStartVnode = newCh[++newStartIdx];
@ -481,8 +486,9 @@ BI.Layout = BI.inherit(BI.Widget, {
insertBefore(node, oldStartVnode); insertBefore(node, oldStartVnode);
} else { // 如果新节点在旧节点区间中存在就复用一下 } else { // 如果新节点在旧节点区间中存在就复用一下
var sameOldIndex = sameOldVnode[1]; var sameOldIndex = sameOldVnode[1];
updated = self.patchItem(sameOldVnode[0], newStartVnode, sameOldIndex, newStartIdx) || updated; var willUpdate = self.patchItem(sameOldVnode[0], newStartVnode, sameOldIndex, newStartIdx);
children[sameOldVnode[0].key == null ? newStartIdx : sameOldVnode[0].key] = self._children[self._getChildName(sameOldIndex)]; updated = willUpdate || updated;
children[sameOldVnode[0].key == null ? newStartIdx : sameOldVnode[0].key] = willUpdate ? this._children[this._getChildName(newStartIdx) + "-temp"] : self._children[self._getChildName(sameOldIndex)];
oldCh[sameOldIndex] = undefined; oldCh[sameOldIndex] = undefined;
insertBefore(sameOldVnode[0], oldStartVnode); insertBefore(sameOldVnode[0], oldStartVnode);
} }

Loading…
Cancel
Save