Browse Source

Merge pull request #135 in FUI/fineui from ~GUY/fineui:master to master

* commit '7b87b6f8ba43e63451bfa356a3c7f1eb2a470b78':
  表格性能优化
es6
guy 7 years ago
parent
commit
759da96b35
  1. 45
      bi/base.js
  2. 45
      dist/base.js
  3. 45
      dist/bundle.js
  4. 20
      src/base/collection/collection.js
  5. 25
      src/base/grid/grid.js

45
bi/base.js

@ -2796,7 +2796,7 @@ BI.CollectionView = BI.inherit(BI.Widget, {
return; return;
} }
var childrenToDisplay = this._cellRenderers(bottom - top, right - left, left, top); var childrenToDisplay = this._cellRenderers(bottom - top, right - left, left, top);
var renderedCells = [], renderedKeys = [], renderedWidgets = {}; var renderedCells = [], renderedKeys = {}, renderedWidgets = {};
//存储所有的left和top //存储所有的left和top
var lefts = {}, tops = {}; var lefts = {}, tops = {};
for (var i = 0, len = childrenToDisplay.length; i < len; i++) { for (var i = 0, len = childrenToDisplay.length; i < len; i++) {
@ -2824,9 +2824,9 @@ BI.CollectionView = BI.inherit(BI.Widget, {
}; };
for (var i = 0, len = childrenToDisplay.length; i < len; i++) { for (var i = 0, len = childrenToDisplay.length; i < len; i++) {
var datum = childrenToDisplay[i]; var datum = childrenToDisplay[i];
var index = BI.deepIndexOf(this.renderedKeys, datum.index); var index = this.renderedKeys[datum.index] && this.renderedKeys[datum.index][1];
var child; var child;
if (index > -1) { if (index >= 0) {
if (datum.width !== this.renderedCells[index]._width) { if (datum.width !== this.renderedCells[index]._width) {
this.renderedCells[index]._width = datum.width; this.renderedCells[index]._width = datum.width;
this.renderedCells[index].el.setWidth(datum.width); this.renderedCells[index].el.setWidth(datum.width);
@ -2881,34 +2881,34 @@ BI.CollectionView = BI.inherit(BI.Widget, {
bottomBorder[l] = Math.max(bottomBorder[l], datum.y + datum.height); bottomBorder[l] = Math.max(bottomBorder[l], datum.y + datum.height);
} }
renderedKeys.push(datum.index); renderedKeys[datum.index] = [datum.index, i];
renderedWidgets[i] = child; renderedWidgets[i] = child;
} }
//已存在的, 需要添加的和需要删除的 //已存在的, 需要添加的和需要删除的
var existSet = {}, addSet = {}, deleteArray = []; var existSet = {}, addSet = {}, deleteArray = [];
BI.each(renderedKeys, function (i, key) { BI.each(renderedKeys, function (i, key) {
if (BI.deepContains(self.renderedKeys, key)) { if (self.renderedKeys[i]) {
existSet[i] = key; existSet[i] = key;
} else { } else {
addSet[i] = key; addSet[i] = key;
} }
}); });
BI.each(this.renderedKeys, function (i, key) { BI.each(this.renderedKeys, function (i, key) {
if (BI.deepContains(existSet, key)) { if (existSet[i]) {
return; return;
} }
if (BI.deepContains(addSet, key)) { if (addSet[i]) {
return; return;
} }
deleteArray.push(i); deleteArray.push(key[1]);
}); });
BI.each(deleteArray, function (i, index) { BI.each(deleteArray, function (i, index) {
//性能优化,不调用destroy方法防止触发destroy事件 //性能优化,不调用destroy方法防止触发destroy事件
self.renderedCells[index].el._destroy(); self.renderedCells[index].el._destroy();
}); });
var addedItems = []; var addedItems = [];
BI.each(addSet, function (index) { BI.each(addSet, function (index, key) {
addedItems.push(renderedCells[index]) addedItems.push(renderedCells[key[1]])
}); });
this.container.addItems(addedItems); this.container.addItems(addedItems);
//拦截父子级关系 //拦截父子级关系
@ -14975,19 +14975,19 @@ BI.GridView = BI.inherit(BI.Widget, {
return; return;
} }
var renderedCells = [], renderedKeys = [], renderedWidgets = {}; var renderedCells = [], renderedKeys = {}, renderedWidgets = {};
var minX = this._getMaxScrollLeft(), minY = this._getMaxScrollTop(), maxX = 0, maxY = 0; var minX = this._getMaxScrollLeft(), minY = this._getMaxScrollTop(), maxX = 0, maxY = 0;
var count = 0; var count = 0;
for (var rowIndex = rowStartIndex; rowIndex <= rowStopIndex; rowIndex++) { for (var rowIndex = rowStartIndex; rowIndex <= rowStopIndex; rowIndex++) {
var rowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowIndex); var rowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowIndex);
for (var columnIndex = columnStartIndex; columnIndex <= columnStopIndex; columnIndex++) { for (var columnIndex = columnStartIndex; columnIndex <= columnStopIndex; columnIndex++) {
var key = [rowIndex, columnIndex]; var key = rowIndex + "-" + columnIndex;
var columnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnIndex); var columnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnIndex);
var index = BI.deepIndexOf(this.renderedKeys, key); var index = this.renderedKeys[key] && this.renderedKeys[key][2];
var child; var child;
if (index > -1) { if (index >= 0) {
if (columnDatum.size !== this.renderedCells[index]._width) { if (columnDatum.size !== this.renderedCells[index]._width) {
this.renderedCells[index]._width = columnDatum.size; this.renderedCells[index]._width = columnDatum.size;
this.renderedCells[index].el.setWidth(columnDatum.size); this.renderedCells[index].el.setWidth(columnDatum.size);
@ -15029,35 +15029,36 @@ BI.GridView = BI.inherit(BI.Widget, {
maxX = Math.max(maxX, columnDatum.offset + horizontalOffsetAdjustment + columnDatum.size); maxX = Math.max(maxX, columnDatum.offset + horizontalOffsetAdjustment + columnDatum.size);
minY = Math.min(minY, rowDatum.offset + verticalOffsetAdjustment); minY = Math.min(minY, rowDatum.offset + verticalOffsetAdjustment);
maxY = Math.max(maxY, rowDatum.offset + verticalOffsetAdjustment + rowDatum.size); maxY = Math.max(maxY, rowDatum.offset + verticalOffsetAdjustment + rowDatum.size);
renderedKeys.push(key); renderedKeys[key] = [rowIndex, columnIndex, count];
renderedWidgets[count++] = child; renderedWidgets[count] = child;
count++;
} }
} }
//已存在的, 需要添加的和需要删除的 //已存在的, 需要添加的和需要删除的
var existSet = {}, addSet = {}, deleteArray = []; var existSet = {}, addSet = {}, deleteArray = [];
BI.each(renderedKeys, function (i, key) { BI.each(renderedKeys, function (i, key) {
if (BI.deepContains(self.renderedKeys, key)) { if (self.renderedKeys[i]) {
existSet[i] = key; existSet[i] = key;
} else { } else {
addSet[i] = key; addSet[i] = key;
} }
}); });
BI.each(this.renderedKeys, function (i, key) { BI.each(this.renderedKeys, function (i, key) {
if (BI.deepContains(existSet, key)) { if (existSet[i]) {
return; return;
} }
if (BI.deepContains(addSet, key)) { if (addSet[i]) {
return; return;
} }
deleteArray.push(i); deleteArray.push(key[2]);
}); });
BI.each(deleteArray, function (i, index) { BI.each(deleteArray, function (i, index) {
//性能优化,不调用destroy方法防止触发destroy事件 //性能优化,不调用destroy方法防止触发destroy事件
self.renderedCells[index].el._destroy(); self.renderedCells[index].el._destroy();
}); });
var addedItems = []; var addedItems = [];
BI.each(addSet, function (index) { BI.each(addSet, function (index, key) {
addedItems.push(renderedCells[index]) addedItems.push(renderedCells[key[2]])
}); });
this.container.addItems(addedItems); this.container.addItems(addedItems);
//拦截父子级关系 //拦截父子级关系

45
dist/base.js vendored

@ -2796,7 +2796,7 @@ BI.CollectionView = BI.inherit(BI.Widget, {
return; return;
} }
var childrenToDisplay = this._cellRenderers(bottom - top, right - left, left, top); var childrenToDisplay = this._cellRenderers(bottom - top, right - left, left, top);
var renderedCells = [], renderedKeys = [], renderedWidgets = {}; var renderedCells = [], renderedKeys = {}, renderedWidgets = {};
//存储所有的left和top //存储所有的left和top
var lefts = {}, tops = {}; var lefts = {}, tops = {};
for (var i = 0, len = childrenToDisplay.length; i < len; i++) { for (var i = 0, len = childrenToDisplay.length; i < len; i++) {
@ -2824,9 +2824,9 @@ BI.CollectionView = BI.inherit(BI.Widget, {
}; };
for (var i = 0, len = childrenToDisplay.length; i < len; i++) { for (var i = 0, len = childrenToDisplay.length; i < len; i++) {
var datum = childrenToDisplay[i]; var datum = childrenToDisplay[i];
var index = BI.deepIndexOf(this.renderedKeys, datum.index); var index = this.renderedKeys[datum.index] && this.renderedKeys[datum.index][1];
var child; var child;
if (index > -1) { if (index >= 0) {
if (datum.width !== this.renderedCells[index]._width) { if (datum.width !== this.renderedCells[index]._width) {
this.renderedCells[index]._width = datum.width; this.renderedCells[index]._width = datum.width;
this.renderedCells[index].el.setWidth(datum.width); this.renderedCells[index].el.setWidth(datum.width);
@ -2881,34 +2881,34 @@ BI.CollectionView = BI.inherit(BI.Widget, {
bottomBorder[l] = Math.max(bottomBorder[l], datum.y + datum.height); bottomBorder[l] = Math.max(bottomBorder[l], datum.y + datum.height);
} }
renderedKeys.push(datum.index); renderedKeys[datum.index] = [datum.index, i];
renderedWidgets[i] = child; renderedWidgets[i] = child;
} }
//已存在的, 需要添加的和需要删除的 //已存在的, 需要添加的和需要删除的
var existSet = {}, addSet = {}, deleteArray = []; var existSet = {}, addSet = {}, deleteArray = [];
BI.each(renderedKeys, function (i, key) { BI.each(renderedKeys, function (i, key) {
if (BI.deepContains(self.renderedKeys, key)) { if (self.renderedKeys[i]) {
existSet[i] = key; existSet[i] = key;
} else { } else {
addSet[i] = key; addSet[i] = key;
} }
}); });
BI.each(this.renderedKeys, function (i, key) { BI.each(this.renderedKeys, function (i, key) {
if (BI.deepContains(existSet, key)) { if (existSet[i]) {
return; return;
} }
if (BI.deepContains(addSet, key)) { if (addSet[i]) {
return; return;
} }
deleteArray.push(i); deleteArray.push(key[1]);
}); });
BI.each(deleteArray, function (i, index) { BI.each(deleteArray, function (i, index) {
//性能优化,不调用destroy方法防止触发destroy事件 //性能优化,不调用destroy方法防止触发destroy事件
self.renderedCells[index].el._destroy(); self.renderedCells[index].el._destroy();
}); });
var addedItems = []; var addedItems = [];
BI.each(addSet, function (index) { BI.each(addSet, function (index, key) {
addedItems.push(renderedCells[index]) addedItems.push(renderedCells[key[1]])
}); });
this.container.addItems(addedItems); this.container.addItems(addedItems);
//拦截父子级关系 //拦截父子级关系
@ -14975,19 +14975,19 @@ BI.GridView = BI.inherit(BI.Widget, {
return; return;
} }
var renderedCells = [], renderedKeys = [], renderedWidgets = {}; var renderedCells = [], renderedKeys = {}, renderedWidgets = {};
var minX = this._getMaxScrollLeft(), minY = this._getMaxScrollTop(), maxX = 0, maxY = 0; var minX = this._getMaxScrollLeft(), minY = this._getMaxScrollTop(), maxX = 0, maxY = 0;
var count = 0; var count = 0;
for (var rowIndex = rowStartIndex; rowIndex <= rowStopIndex; rowIndex++) { for (var rowIndex = rowStartIndex; rowIndex <= rowStopIndex; rowIndex++) {
var rowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowIndex); var rowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowIndex);
for (var columnIndex = columnStartIndex; columnIndex <= columnStopIndex; columnIndex++) { for (var columnIndex = columnStartIndex; columnIndex <= columnStopIndex; columnIndex++) {
var key = [rowIndex, columnIndex]; var key = rowIndex + "-" + columnIndex;
var columnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnIndex); var columnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnIndex);
var index = BI.deepIndexOf(this.renderedKeys, key); var index = this.renderedKeys[key] && this.renderedKeys[key][2];
var child; var child;
if (index > -1) { if (index >= 0) {
if (columnDatum.size !== this.renderedCells[index]._width) { if (columnDatum.size !== this.renderedCells[index]._width) {
this.renderedCells[index]._width = columnDatum.size; this.renderedCells[index]._width = columnDatum.size;
this.renderedCells[index].el.setWidth(columnDatum.size); this.renderedCells[index].el.setWidth(columnDatum.size);
@ -15029,35 +15029,36 @@ BI.GridView = BI.inherit(BI.Widget, {
maxX = Math.max(maxX, columnDatum.offset + horizontalOffsetAdjustment + columnDatum.size); maxX = Math.max(maxX, columnDatum.offset + horizontalOffsetAdjustment + columnDatum.size);
minY = Math.min(minY, rowDatum.offset + verticalOffsetAdjustment); minY = Math.min(minY, rowDatum.offset + verticalOffsetAdjustment);
maxY = Math.max(maxY, rowDatum.offset + verticalOffsetAdjustment + rowDatum.size); maxY = Math.max(maxY, rowDatum.offset + verticalOffsetAdjustment + rowDatum.size);
renderedKeys.push(key); renderedKeys[key] = [rowIndex, columnIndex, count];
renderedWidgets[count++] = child; renderedWidgets[count] = child;
count++;
} }
} }
//已存在的, 需要添加的和需要删除的 //已存在的, 需要添加的和需要删除的
var existSet = {}, addSet = {}, deleteArray = []; var existSet = {}, addSet = {}, deleteArray = [];
BI.each(renderedKeys, function (i, key) { BI.each(renderedKeys, function (i, key) {
if (BI.deepContains(self.renderedKeys, key)) { if (self.renderedKeys[i]) {
existSet[i] = key; existSet[i] = key;
} else { } else {
addSet[i] = key; addSet[i] = key;
} }
}); });
BI.each(this.renderedKeys, function (i, key) { BI.each(this.renderedKeys, function (i, key) {
if (BI.deepContains(existSet, key)) { if (existSet[i]) {
return; return;
} }
if (BI.deepContains(addSet, key)) { if (addSet[i]) {
return; return;
} }
deleteArray.push(i); deleteArray.push(key[2]);
}); });
BI.each(deleteArray, function (i, index) { BI.each(deleteArray, function (i, index) {
//性能优化,不调用destroy方法防止触发destroy事件 //性能优化,不调用destroy方法防止触发destroy事件
self.renderedCells[index].el._destroy(); self.renderedCells[index].el._destroy();
}); });
var addedItems = []; var addedItems = [];
BI.each(addSet, function (index) { BI.each(addSet, function (index, key) {
addedItems.push(renderedCells[index]) addedItems.push(renderedCells[key[2]])
}); });
this.container.addItems(addedItems); this.container.addItems(addedItems);
//拦截父子级关系 //拦截父子级关系

45
dist/bundle.js vendored

@ -31667,7 +31667,7 @@ BI.CollectionView = BI.inherit(BI.Widget, {
return; return;
} }
var childrenToDisplay = this._cellRenderers(bottom - top, right - left, left, top); var childrenToDisplay = this._cellRenderers(bottom - top, right - left, left, top);
var renderedCells = [], renderedKeys = [], renderedWidgets = {}; var renderedCells = [], renderedKeys = {}, renderedWidgets = {};
//存储所有的left和top //存储所有的left和top
var lefts = {}, tops = {}; var lefts = {}, tops = {};
for (var i = 0, len = childrenToDisplay.length; i < len; i++) { for (var i = 0, len = childrenToDisplay.length; i < len; i++) {
@ -31695,9 +31695,9 @@ BI.CollectionView = BI.inherit(BI.Widget, {
}; };
for (var i = 0, len = childrenToDisplay.length; i < len; i++) { for (var i = 0, len = childrenToDisplay.length; i < len; i++) {
var datum = childrenToDisplay[i]; var datum = childrenToDisplay[i];
var index = BI.deepIndexOf(this.renderedKeys, datum.index); var index = this.renderedKeys[datum.index] && this.renderedKeys[datum.index][1];
var child; var child;
if (index > -1) { if (index >= 0) {
if (datum.width !== this.renderedCells[index]._width) { if (datum.width !== this.renderedCells[index]._width) {
this.renderedCells[index]._width = datum.width; this.renderedCells[index]._width = datum.width;
this.renderedCells[index].el.setWidth(datum.width); this.renderedCells[index].el.setWidth(datum.width);
@ -31752,34 +31752,34 @@ BI.CollectionView = BI.inherit(BI.Widget, {
bottomBorder[l] = Math.max(bottomBorder[l], datum.y + datum.height); bottomBorder[l] = Math.max(bottomBorder[l], datum.y + datum.height);
} }
renderedKeys.push(datum.index); renderedKeys[datum.index] = [datum.index, i];
renderedWidgets[i] = child; renderedWidgets[i] = child;
} }
//已存在的, 需要添加的和需要删除的 //已存在的, 需要添加的和需要删除的
var existSet = {}, addSet = {}, deleteArray = []; var existSet = {}, addSet = {}, deleteArray = [];
BI.each(renderedKeys, function (i, key) { BI.each(renderedKeys, function (i, key) {
if (BI.deepContains(self.renderedKeys, key)) { if (self.renderedKeys[i]) {
existSet[i] = key; existSet[i] = key;
} else { } else {
addSet[i] = key; addSet[i] = key;
} }
}); });
BI.each(this.renderedKeys, function (i, key) { BI.each(this.renderedKeys, function (i, key) {
if (BI.deepContains(existSet, key)) { if (existSet[i]) {
return; return;
} }
if (BI.deepContains(addSet, key)) { if (addSet[i]) {
return; return;
} }
deleteArray.push(i); deleteArray.push(key[1]);
}); });
BI.each(deleteArray, function (i, index) { BI.each(deleteArray, function (i, index) {
//性能优化,不调用destroy方法防止触发destroy事件 //性能优化,不调用destroy方法防止触发destroy事件
self.renderedCells[index].el._destroy(); self.renderedCells[index].el._destroy();
}); });
var addedItems = []; var addedItems = [];
BI.each(addSet, function (index) { BI.each(addSet, function (index, key) {
addedItems.push(renderedCells[index]) addedItems.push(renderedCells[key[1]])
}); });
this.container.addItems(addedItems); this.container.addItems(addedItems);
//拦截父子级关系 //拦截父子级关系
@ -43846,19 +43846,19 @@ BI.GridView = BI.inherit(BI.Widget, {
return; return;
} }
var renderedCells = [], renderedKeys = [], renderedWidgets = {}; var renderedCells = [], renderedKeys = {}, renderedWidgets = {};
var minX = this._getMaxScrollLeft(), minY = this._getMaxScrollTop(), maxX = 0, maxY = 0; var minX = this._getMaxScrollLeft(), minY = this._getMaxScrollTop(), maxX = 0, maxY = 0;
var count = 0; var count = 0;
for (var rowIndex = rowStartIndex; rowIndex <= rowStopIndex; rowIndex++) { for (var rowIndex = rowStartIndex; rowIndex <= rowStopIndex; rowIndex++) {
var rowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowIndex); var rowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowIndex);
for (var columnIndex = columnStartIndex; columnIndex <= columnStopIndex; columnIndex++) { for (var columnIndex = columnStartIndex; columnIndex <= columnStopIndex; columnIndex++) {
var key = [rowIndex, columnIndex]; var key = rowIndex + "-" + columnIndex;
var columnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnIndex); var columnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnIndex);
var index = BI.deepIndexOf(this.renderedKeys, key); var index = this.renderedKeys[key] && this.renderedKeys[key][2];
var child; var child;
if (index > -1) { if (index >= 0) {
if (columnDatum.size !== this.renderedCells[index]._width) { if (columnDatum.size !== this.renderedCells[index]._width) {
this.renderedCells[index]._width = columnDatum.size; this.renderedCells[index]._width = columnDatum.size;
this.renderedCells[index].el.setWidth(columnDatum.size); this.renderedCells[index].el.setWidth(columnDatum.size);
@ -43900,35 +43900,36 @@ BI.GridView = BI.inherit(BI.Widget, {
maxX = Math.max(maxX, columnDatum.offset + horizontalOffsetAdjustment + columnDatum.size); maxX = Math.max(maxX, columnDatum.offset + horizontalOffsetAdjustment + columnDatum.size);
minY = Math.min(minY, rowDatum.offset + verticalOffsetAdjustment); minY = Math.min(minY, rowDatum.offset + verticalOffsetAdjustment);
maxY = Math.max(maxY, rowDatum.offset + verticalOffsetAdjustment + rowDatum.size); maxY = Math.max(maxY, rowDatum.offset + verticalOffsetAdjustment + rowDatum.size);
renderedKeys.push(key); renderedKeys[key] = [rowIndex, columnIndex, count];
renderedWidgets[count++] = child; renderedWidgets[count] = child;
count++;
} }
} }
//已存在的, 需要添加的和需要删除的 //已存在的, 需要添加的和需要删除的
var existSet = {}, addSet = {}, deleteArray = []; var existSet = {}, addSet = {}, deleteArray = [];
BI.each(renderedKeys, function (i, key) { BI.each(renderedKeys, function (i, key) {
if (BI.deepContains(self.renderedKeys, key)) { if (self.renderedKeys[i]) {
existSet[i] = key; existSet[i] = key;
} else { } else {
addSet[i] = key; addSet[i] = key;
} }
}); });
BI.each(this.renderedKeys, function (i, key) { BI.each(this.renderedKeys, function (i, key) {
if (BI.deepContains(existSet, key)) { if (existSet[i]) {
return; return;
} }
if (BI.deepContains(addSet, key)) { if (addSet[i]) {
return; return;
} }
deleteArray.push(i); deleteArray.push(key[2]);
}); });
BI.each(deleteArray, function (i, index) { BI.each(deleteArray, function (i, index) {
//性能优化,不调用destroy方法防止触发destroy事件 //性能优化,不调用destroy方法防止触发destroy事件
self.renderedCells[index].el._destroy(); self.renderedCells[index].el._destroy();
}); });
var addedItems = []; var addedItems = [];
BI.each(addSet, function (index) { BI.each(addSet, function (index, key) {
addedItems.push(renderedCells[index]) addedItems.push(renderedCells[key[2]])
}); });
this.container.addItems(addedItems); this.container.addItems(addedItems);
//拦截父子级关系 //拦截父子级关系

20
src/base/collection/collection.js

@ -127,7 +127,7 @@ BI.CollectionView = BI.inherit(BI.Widget, {
return; return;
} }
var childrenToDisplay = this._cellRenderers(bottom - top, right - left, left, top); var childrenToDisplay = this._cellRenderers(bottom - top, right - left, left, top);
var renderedCells = [], renderedKeys = [], renderedWidgets = {}; var renderedCells = [], renderedKeys = {}, renderedWidgets = {};
//存储所有的left和top //存储所有的left和top
var lefts = {}, tops = {}; var lefts = {}, tops = {};
for (var i = 0, len = childrenToDisplay.length; i < len; i++) { for (var i = 0, len = childrenToDisplay.length; i < len; i++) {
@ -155,9 +155,9 @@ BI.CollectionView = BI.inherit(BI.Widget, {
}; };
for (var i = 0, len = childrenToDisplay.length; i < len; i++) { for (var i = 0, len = childrenToDisplay.length; i < len; i++) {
var datum = childrenToDisplay[i]; var datum = childrenToDisplay[i];
var index = BI.deepIndexOf(this.renderedKeys, datum.index); var index = this.renderedKeys[datum.index] && this.renderedKeys[datum.index][1];
var child; var child;
if (index > -1) { if (index >= 0) {
if (datum.width !== this.renderedCells[index]._width) { if (datum.width !== this.renderedCells[index]._width) {
this.renderedCells[index]._width = datum.width; this.renderedCells[index]._width = datum.width;
this.renderedCells[index].el.setWidth(datum.width); this.renderedCells[index].el.setWidth(datum.width);
@ -212,34 +212,34 @@ BI.CollectionView = BI.inherit(BI.Widget, {
bottomBorder[l] = Math.max(bottomBorder[l], datum.y + datum.height); bottomBorder[l] = Math.max(bottomBorder[l], datum.y + datum.height);
} }
renderedKeys.push(datum.index); renderedKeys[datum.index] = [datum.index, i];
renderedWidgets[i] = child; renderedWidgets[i] = child;
} }
//已存在的, 需要添加的和需要删除的 //已存在的, 需要添加的和需要删除的
var existSet = {}, addSet = {}, deleteArray = []; var existSet = {}, addSet = {}, deleteArray = [];
BI.each(renderedKeys, function (i, key) { BI.each(renderedKeys, function (i, key) {
if (BI.deepContains(self.renderedKeys, key)) { if (self.renderedKeys[i]) {
existSet[i] = key; existSet[i] = key;
} else { } else {
addSet[i] = key; addSet[i] = key;
} }
}); });
BI.each(this.renderedKeys, function (i, key) { BI.each(this.renderedKeys, function (i, key) {
if (BI.deepContains(existSet, key)) { if (existSet[i]) {
return; return;
} }
if (BI.deepContains(addSet, key)) { if (addSet[i]) {
return; return;
} }
deleteArray.push(i); deleteArray.push(key[1]);
}); });
BI.each(deleteArray, function (i, index) { BI.each(deleteArray, function (i, index) {
//性能优化,不调用destroy方法防止触发destroy事件 //性能优化,不调用destroy方法防止触发destroy事件
self.renderedCells[index].el._destroy(); self.renderedCells[index].el._destroy();
}); });
var addedItems = []; var addedItems = [];
BI.each(addSet, function (index) { BI.each(addSet, function (index, key) {
addedItems.push(renderedCells[index]) addedItems.push(renderedCells[key[1]])
}); });
this.container.addItems(addedItems); this.container.addItems(addedItems);
//拦截父子级关系 //拦截父子级关系

25
src/base/grid/grid.js

@ -121,19 +121,19 @@ BI.GridView = BI.inherit(BI.Widget, {
return; return;
} }
var renderedCells = [], renderedKeys = [], renderedWidgets = {}; var renderedCells = [], renderedKeys = {}, renderedWidgets = {};
var minX = this._getMaxScrollLeft(), minY = this._getMaxScrollTop(), maxX = 0, maxY = 0; var minX = this._getMaxScrollLeft(), minY = this._getMaxScrollTop(), maxX = 0, maxY = 0;
var count = 0; var count = 0;
for (var rowIndex = rowStartIndex; rowIndex <= rowStopIndex; rowIndex++) { for (var rowIndex = rowStartIndex; rowIndex <= rowStopIndex; rowIndex++) {
var rowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowIndex); var rowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowIndex);
for (var columnIndex = columnStartIndex; columnIndex <= columnStopIndex; columnIndex++) { for (var columnIndex = columnStartIndex; columnIndex <= columnStopIndex; columnIndex++) {
var key = [rowIndex, columnIndex]; var key = rowIndex + "-" + columnIndex;
var columnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnIndex); var columnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnIndex);
var index = BI.deepIndexOf(this.renderedKeys, key); var index = this.renderedKeys[key] && this.renderedKeys[key][2];
var child; var child;
if (index > -1) { if (index >= 0) {
if (columnDatum.size !== this.renderedCells[index]._width) { if (columnDatum.size !== this.renderedCells[index]._width) {
this.renderedCells[index]._width = columnDatum.size; this.renderedCells[index]._width = columnDatum.size;
this.renderedCells[index].el.setWidth(columnDatum.size); this.renderedCells[index].el.setWidth(columnDatum.size);
@ -175,35 +175,36 @@ BI.GridView = BI.inherit(BI.Widget, {
maxX = Math.max(maxX, columnDatum.offset + horizontalOffsetAdjustment + columnDatum.size); maxX = Math.max(maxX, columnDatum.offset + horizontalOffsetAdjustment + columnDatum.size);
minY = Math.min(minY, rowDatum.offset + verticalOffsetAdjustment); minY = Math.min(minY, rowDatum.offset + verticalOffsetAdjustment);
maxY = Math.max(maxY, rowDatum.offset + verticalOffsetAdjustment + rowDatum.size); maxY = Math.max(maxY, rowDatum.offset + verticalOffsetAdjustment + rowDatum.size);
renderedKeys.push(key); renderedKeys[key] = [rowIndex, columnIndex, count];
renderedWidgets[count++] = child; renderedWidgets[count] = child;
count++;
} }
} }
//已存在的, 需要添加的和需要删除的 //已存在的, 需要添加的和需要删除的
var existSet = {}, addSet = {}, deleteArray = []; var existSet = {}, addSet = {}, deleteArray = [];
BI.each(renderedKeys, function (i, key) { BI.each(renderedKeys, function (i, key) {
if (BI.deepContains(self.renderedKeys, key)) { if (self.renderedKeys[i]) {
existSet[i] = key; existSet[i] = key;
} else { } else {
addSet[i] = key; addSet[i] = key;
} }
}); });
BI.each(this.renderedKeys, function (i, key) { BI.each(this.renderedKeys, function (i, key) {
if (BI.deepContains(existSet, key)) { if (existSet[i]) {
return; return;
} }
if (BI.deepContains(addSet, key)) { if (addSet[i]) {
return; return;
} }
deleteArray.push(i); deleteArray.push(key[2]);
}); });
BI.each(deleteArray, function (i, index) { BI.each(deleteArray, function (i, index) {
//性能优化,不调用destroy方法防止触发destroy事件 //性能优化,不调用destroy方法防止触发destroy事件
self.renderedCells[index].el._destroy(); self.renderedCells[index].el._destroy();
}); });
var addedItems = []; var addedItems = [];
BI.each(addSet, function (index) { BI.each(addSet, function (index, key) {
addedItems.push(renderedCells[index]) addedItems.push(renderedCells[key[2]])
}); });
this.container.addItems(addedItems); this.container.addItems(addedItems);
//拦截父子级关系 //拦截父子级关系

Loading…
Cancel
Save