diff --git a/src/base/grid/grid.js b/src/base/grid/grid.js index dbc06bb70f..b7c5c80206 100644 --- a/src/base/grid/grid.js +++ b/src/base/grid/grid.js @@ -208,7 +208,8 @@ BI.GridView = BI.inherit(BI.Widget, { BI.each(addSet, function (index, key) { addedItems.push(renderedCells[key[2]]); }); - this.container.addItems(addedItems); + // 与listview一样, 给上下文 + this.container.addItems(addedItems, this); // 拦截父子级关系 this.container._children = renderedWidgets; this.container.attr("items", renderedCells); diff --git a/src/base/list/virtuallist.js b/src/base/list/virtuallist.js index 041941e5fc..e5d996bcd8 100644 --- a/src/base/list/virtuallist.js +++ b/src/base/list/virtuallist.js @@ -151,7 +151,7 @@ BI.VirtualList = BI.inherit(BI.Widget, { _clearChildren: function () { BI.each(this.container._children, function (i, cell) { - cell && cell.el._destroy(); + cell && cell._destroy(); }); this.container._children = {}; this.container.attr("items", []); @@ -162,6 +162,9 @@ BI.VirtualList = BI.inherit(BI.Widget, { this._clearChildren(); this.cache = {}; this.options.scrollTop = 0; + // 依赖于cache的占位元素也要初始化 + this.topBlank.setHeight(0); + this.bottomBlank.setHeight(0); }, populate: function (items) { diff --git a/src/core/utils/prefixIntervalTree.js b/src/core/utils/prefixIntervalTree.js index 1a1b32044a..1a180b34d9 100644 --- a/src/core/utils/prefixIntervalTree.js +++ b/src/core/utils/prefixIntervalTree.js @@ -23,13 +23,15 @@ BI.PrefixIntervalTree = function (xs) { this._size = xs.length; this._half = ceilLog2(this._size); + // _heap是一个_size两倍以上的堆 this._heap = new Int32Array(2 * this._half); var i; + // 初始化 >= _size 的堆空间, 即叶子节点 for (i = 0; i < this._size; ++i) { this._heap[this._half + i] = xs[i]; } - + // 初始化 < _size 的堆空间, 即非叶子节点,根节点包含整个区间 for (i = this._half - 1; i > 0; --i) { this._heap[i] = this._heap[2 * i] + this._heap[2 * i + 1]; } @@ -37,6 +39,7 @@ BI.PrefixIntervalTree.prototype = { constructor: BI.PrefixIntervalTree, + // 往_half之后的空间set值,需要更新其所有祖先节点的值 set: function (index, value) { var node = this._half + index; this._heap[node] = value;