diff --git a/src/base/collection/collection.js b/src/base/collection/collection.js index 871d77d4d..fa16883e4 100644 --- a/src/base/collection/collection.js +++ b/src/base/collection/collection.js @@ -276,19 +276,17 @@ BI.CollectionView = BI.inherit(BI.Widget, { this.options.items = items; this._calculateSizeAndPositionData(); } - if (o.items.length > 0) { - this.container.setWidth(this._width); - this.container.setHeight(this._height); + this.container.setWidth(this._width); + this.container.setHeight(this._height); - this._debounceRelease(); - // 元素未挂载时不能设置scrollTop - try { - this.element.scrollTop(o.scrollTop); - this.element.scrollLeft(o.scrollLeft); - } catch (e) { - } - this._calculateChildrenToRender(); + this._debounceRelease(); + // 元素未挂载时不能设置scrollTop + try { + this.element.scrollTop(o.scrollTop); + this.element.scrollLeft(o.scrollLeft); + } catch (e) { } + this._calculateChildrenToRender(); }, setScrollLeft: function (scrollLeft) { diff --git a/src/base/grid/grid.js b/src/base/grid/grid.js index 3cfa530c4..6096a28c5 100644 --- a/src/base/grid/grid.js +++ b/src/base/grid/grid.js @@ -262,22 +262,17 @@ BI.GridView = BI.inherit(BI.Widget, { this.options.items = items; this._calculateSizeAndPositionData(); } - if (o.items.length > 0) { - this.container.setWidth(this._getContainerWidth()); - this.container.setHeight(this._getContainerHeight()); - - // 元素未挂载时不能设置scrollTop - this._debounceRelease(); - try { - this.element.scrollTop(o.scrollTop); - this.element.scrollLeft(o.scrollLeft); - } catch (e) { - } - this._calculateChildrenToRender(); - } else { - this.container.setWidth("auto"); - this.container.setHeight("auto"); + this.container.setWidth(this._getContainerWidth()); + this.container.setHeight(this._getContainerHeight()); + + // 元素未挂载时不能设置scrollTop + this._debounceRelease(); + try { + this.element.scrollTop(o.scrollTop); + this.element.scrollLeft(o.scrollLeft); + } catch (e) { } + this._calculateChildrenToRender(); }, setScrollLeft: function (scrollLeft) {