Browse Source

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

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

29
src/core/wrapper/layout.js

@ -421,9 +421,22 @@ BI.Layout = BI.inherit(BI.Widget, {
oldEndVnode = oldCh[--oldEndIdx]; oldEndVnode = oldCh[--oldEndIdx];
newStartVnode = newCh[++newStartIdx]; newStartVnode = newCh[++newStartIdx];
} else { } else {
var sameOldVnode = findOldVnode(oldCh, newStartVnode, oldStartIdx, oldEndIdx);
if (BI.isNull(sameOldVnode)) { // 不存在就把新的放到左边
var node = addNode(newStartVnode); var node = addNode(newStartVnode);
insertBefore(node, oldStartVnode); insertBefore(node, oldStartVnode);
newStartVnode = newCh[++newStartIdx]; 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) { if (oldStartIdx > oldEndIdx) {
@ -467,11 +480,15 @@ BI.Layout = BI.inherit(BI.Widget, {
function removeVnodes (vnodes, startIdx, endIdx) { function removeVnodes (vnodes, startIdx, endIdx) {
for (; startIdx <= endIdx; ++startIdx) { for (; startIdx <= endIdx; ++startIdx) {
var node = self._getOptions(vnodes[startIdx]); var ch = vnodes[startIdx];
if (BI.isNotNull(ch)) {
var node = self._getOptions(ch);
var key = node.key == null ? self._getChildName(startIdx) : node.key; var key = node.key == null ? self._getChildName(startIdx) : node.key;
delete self._children[self._getChildName(key)];
children[key]._destroy(); children[key]._destroy();
} }
} }
}
function insertBefore (insert, before, isNext, index) { function insertBefore (insert, before, isNext, index) {
insert = self._getOptions(insert); insert = self._getOptions(insert);
@ -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; return updated;
}, },

Loading…
Cancel
Save