【发布时间】:2018-05-09 06:34:14
【问题描述】:
我想使用 md-select 向用户显示大量数据。打开 md-select 时,浏览器冻结。因此,作为一种解决方案,我想在 md-select 中使用 md-virtual repeat 以获得更好的性能。但是代码(不只是为我工作。我在这里做错了吗?
<md-input-container flex>
<label>test</label>
<md-select ng-model="$ctrl.haha">
<md-virtual-repeat-container id="vertical-container">
<md-option md-virtual-repeat="item in ctrl.infiniteItems" md-on-demand ng-value="item" ng-selected="$first">
{{item}}
</md-option>
</md-virtual-repeat-container>
</md-select>
</md-input-container>
#vertical-container {
height: 256px;
}
this.infiniteItems = {
numLoaded_: 0,
toLoad_: 0,
items: [],
// Required.
getItemAtIndex(index) {
if (index > this.numLoaded_) {
this.fetchMoreItems_(index);
return null;
}
return this.items[index];
},
// Required.
getLength() {
return this.numLoaded_ + 5;
},
fetchMoreItems_(index) {
if (this.toLoad_ < index) {
this.toLoad_ += 20;
for (let i = 0; i < 10000; i++) {
this.items.push(i);
}
this.numLoaded_ = this.toLoad_;
}
}
};
【问题讨论】:
标签: javascript typescript material-design angular-material