【问题标题】:md-on-demand inside md-autocompletemd-autocomplete 内的 md-on-demand
【发布时间】:2017-08-24 13:41:45
【问题描述】:

如前所述 Angular-Material md-autocomplete 的 documentation:

md-autocomplete 使用 md-virtual-repeat 指令在下拉菜单中显示结果。

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

我了解我必须根据 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 建议,我有无限项对象:

$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 时,我收到消息“未找到”并且加载数据的下拉菜单甚至无法打开。

那么,我做错了什么?

提前致谢!

【问题讨论】:

    标签: angularjs angular-material infinite-scroll md-autocomplete


    【解决方案1】:

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

    md-items="item in infiniteItems"
    

    md-items="item in infiniteItems.items"
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-11
      • 1970-01-01
      • 1970-01-01
      • 2016-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多