Browse Source

无JIRA任务 fix:更新一下layout的updateChildren方法

es6
dailer 5 years ago
parent
commit
737f83f070
  1. 39
      src/core/wrapper/layout.js

39
src/core/wrapper/layout.js

@ -421,9 +421,22 @@ BI.Layout = BI.inherit(BI.Widget, {
oldEndVnode = oldCh[--oldEndIdx];
newStartVnode = newCh[++newStartIdx];
} else {
var node = addNode(newStartVnode);
insertBefore(node, oldStartVnode);
newStartVnode = newCh[++newStartIdx];
var sameOldVnode = findOldVnode(oldCh, newStartVnode, oldStartIdx, oldEndIdx);
if (BI.isNull(sameOldVnode)) { // 不存在就把新的放到左边
var node = addNode(newStartVnode);
insertBefore(node, oldStartVnode);
newStartVnode = newCh[++newStartIdx];
} else { // 如果新节点在就旧节点区间中存在就复用一下
BI.each(oldCh, function (index, child) {
if (child && sameVnode(child, newStartVnode)) {
updated = self.patchItem(sameOldVnode, newStartVnode, index) || updated;
children[sameOldVnode.key == null ? self._getChildName(index) : sameOldVnode.key] = self._children[self._getChildName(index)];
oldCh[index] = undefined;
insertBefore(sameOldVnode, oldStartVnode);
}
});
newStartVnode = newCh[++newStartIdx];
}
}
}
if (oldStartIdx > oldEndIdx) {
@ -467,9 +480,13 @@ BI.Layout = BI.inherit(BI.Widget, {
function removeVnodes (vnodes, startIdx, endIdx) {
for (; startIdx <= endIdx; ++startIdx) {
var node = self._getOptions(vnodes[startIdx]);
var key = node.key == null ? self._getChildName(startIdx) : node.key;
children[key]._destroy();
var ch = vnodes[startIdx];
if (BI.isNotNull(ch)) {
var node = self._getOptions(ch);
var key = node.key == null ? self._getChildName(startIdx) : node.key;
delete self._children[self._getChildName(key)];
children[key]._destroy();
}
}
}
@ -495,6 +512,16 @@ BI.Layout = BI.inherit(BI.Widget, {
}
}
function findOldVnode (vnodes, vNode, beginIdx, endIdx) {
var i, found;
for (i = beginIdx; i <= endIdx; ++i) {
if (vnodes[i] && sameVnode(vnodes[i], vNode)) {
found = vnodes[i];
}
}
return found;
}
return updated;
},

Loading…
Cancel
Save