gpt4 book ai didi

angularjs - md-autocomplete 中的 md-on-demand

转载 作者:行者123 更新时间:2023-12-01 06:03:01 26 4
gpt4 key购买 nike

如前所述 Angular-Material md-autocomplete's documentation :

The md-autocomplete uses the the md-virtual-repeat directive for displaying the results inside of the dropdown.



我遇到了一个问题,我找不到任何片段如何在自动完成中使用虚拟重复。

我知道我必须根据 md-virtual-repeat 的 documentation 使用特定结构进行无限滚动.

我有 md 自动完成功能:
<md-autocomplete
md-no-cache="true"
md-selected-item="obj.selectedItem"
md-search-text="obj.searchText"
md-items="item in infiniteItems"
md-item-text="item.name"
md-on-demand>
<md-item-template>
<span md-highlight-text="obj.searchText" md-highlight-flags="i">{{item.name}}</span>
</md-item-template>
<md-not-found>
not found!
</md-not-found>
</md-autocomplete>

根据 md-virtual-repeat 建议,我有 infiniteItems 对象:
$scope.infiniteItems = {
numLoaded_: 0,
toLoad_: 0,
items: [],

getItemAtIndex: function(index) {
if (index > this.numLoaded_) {
this.fetchMoreItems_(index);
return null;
}

return this.items[index];
},

getLength: function() {
return this.numLoaded_ + 5;
},

fetchMoreItems_: function(index) {

if (this.toLoad_ < index) {
this.toLoad_ += 20;
restService.getData().then(angular.bind(this, function(response) {
this.items = this.items.concat(response.data);
this.numLoaded_ = this.toLoad_;
}));
}
}
}

结果是在加载整个页面后第一次加载数据,当我尝试输入 smth 时,我收到消息“未找到”,加载数据的下拉菜单甚至没有打开。

那么,我做错了什么?

提前致谢!

最佳答案

您的 md-autocomplete 有问题标签属性,更改

md-items="item in infiniteItems"


md-items="item in infiniteItems.items"

您应该能够看到自动完成列表。

关于angularjs - md-autocomplete 中的 md-on-demand,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43121117/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com