加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-17 17:00:22 所属栏目:安全 来源:网络整理
导读:如上所述Angular-Material md-autocomplete的 documentation: The md-autocomplete uses the the md-virtual-repeat directive for displaying the results inside of the dropdown. 我遇到了一个问题,我找不到任何代码片段如何在自动完成内部使用虚拟重复.
如上所述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"

你应该能够看到自动完成列表.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读