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

前端之家收集整理的这篇文章主要介绍了angularjs – md-autocomplete中的md-on-demand前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如上所述Angular-Material md-autocomplete的 documentation

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

我遇到了一个问题,我找不到任何代码片段如何在自动完成内部使用虚拟重复.

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

我有md-autocomplete:

<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相关文章