|
|
|
@ -87,14 +87,17 @@ BI.Layout = BI.inherit(BI.Widget, {
|
|
|
|
|
return "" + index; |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
_addElement: function (i, item, context) { |
|
|
|
|
_addElement: function (i, item, context, widget) { |
|
|
|
|
var self = this, w; |
|
|
|
|
if (widget) { |
|
|
|
|
return widget; |
|
|
|
|
} |
|
|
|
|
if (!this.hasWidget(this._getChildName(i))) { |
|
|
|
|
w = BI._lazyCreateWidget(item, context); |
|
|
|
|
w.on(BI.Events.DESTROY, function () { |
|
|
|
|
BI.each(self._children, function (name, child) { |
|
|
|
|
if (child === w) { |
|
|
|
|
BI.remove(self._children, child); |
|
|
|
|
delete self._children[name]; |
|
|
|
|
self.removeItemAt(name | 0); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
@ -106,6 +109,20 @@ BI.Layout = BI.inherit(BI.Widget, {
|
|
|
|
|
return w; |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
_newElement: function (i, item, context) { |
|
|
|
|
var self = this; |
|
|
|
|
var w = BI._lazyCreateWidget(item, context); |
|
|
|
|
w.on(BI.Events.DESTROY, function () { |
|
|
|
|
BI.each(self._children, function (name, child) { |
|
|
|
|
if (child === w) { |
|
|
|
|
delete self._children[name]; |
|
|
|
|
self.removeItemAt(name | 0); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
return this._addElement(i, item, context, w); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
_getOptions: function (item) { |
|
|
|
|
if (item instanceof BI.Widget) { |
|
|
|
|
item = item.options; |
|
|
|
@ -441,16 +458,12 @@ BI.Layout = BI.inherit(BI.Widget, {
|
|
|
|
|
} else { |
|
|
|
|
var sameOldVnode = findOldVnode(oldCh, newStartVnode, oldStartIdx, oldEndIdx); |
|
|
|
|
if (BI.isNull(sameOldVnode[0])) { // 不存在就把新的放到左边
|
|
|
|
|
delete self._children[self._getChildName(newStartIdx)]; |
|
|
|
|
var node = addNode(newStartVnode, newStartIdx); |
|
|
|
|
insertBefore(node, oldStartVnode); |
|
|
|
|
} else { // 如果新节点在旧节点区间中存在就复用一下
|
|
|
|
|
var sameOldIndex = sameOldVnode[1]; |
|
|
|
|
updated = self.patchItem(sameOldVnode[0], newStartVnode, sameOldIndex, newStartIdx) || updated; |
|
|
|
|
children[sameOldVnode[0].key == null ? newStartIdx : sameOldVnode[0].key] = self._children[self._getChildName(sameOldIndex)]; |
|
|
|
|
if (newStartIdx !== sameOldIndex) { |
|
|
|
|
delete self._children[self._getChildName(sameOldIndex)]; |
|
|
|
|
} |
|
|
|
|
oldCh[sameOldIndex] = undefined; |
|
|
|
|
insertBefore(sameOldVnode[0], oldStartVnode); |
|
|
|
|
} |
|
|
|
@ -468,6 +481,7 @@ BI.Layout = BI.inherit(BI.Widget, {
|
|
|
|
|
BI.each(newCh, function (i, child) { |
|
|
|
|
var node = self._getOptions(child); |
|
|
|
|
var key = node.key == null ? i : node.key; |
|
|
|
|
children[key]._setParent && children[key]._setParent(self); |
|
|
|
|
children[key]._mount(); |
|
|
|
|
self._children[self._getChildName(i)] = children[key]; |
|
|
|
|
}); |
|
|
|
@ -486,8 +500,7 @@ BI.Layout = BI.inherit(BI.Widget, {
|
|
|
|
|
function addNode (vnode, index) { |
|
|
|
|
var opt = self._getOptions(vnode); |
|
|
|
|
var key = opt.key == null ? index : opt.key; |
|
|
|
|
delete self._children[self._getChildName(index)]; |
|
|
|
|
return children[key] = self._addElement(index, vnode); |
|
|
|
|
return children[key] = self._newElement(index, vnode); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function addVnodes (before, vnodes, startIdx, endIdx) { |
|
|
|
@ -503,7 +516,6 @@ BI.Layout = BI.inherit(BI.Widget, {
|
|
|
|
|
if (BI.isNotNull(ch)) { |
|
|
|
|
var node = self._getOptions(ch); |
|
|
|
|
var key = node.key == null ? startIdx : node.key; |
|
|
|
|
delete self._children[self._getChildName(startIdx)]; |
|
|
|
|
children[key]._destroy(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|