第一个列表滚动在聚合物中结束后,铁滚动阈值永远不会执行

2024-02-21

我已经使用以下方法完成了iron-list and iron-scroll-threshold为了在聚合物中实现无限滚动。但问题是 loadMoreDatairon-scroll-threshold在聚合物中第一个列表滚动结束后永远不会执行。请帮助我的代码中缺少或错误的一项。谢谢。

<template>

    <iron-ajax id="ajax" 
      url="https://randomuser.me/api/" 
      handle-as="json" 
      params='{"results": 20}'
      loading="{{loadingPeople}}"
      on-response="categoriesLoaded">
    </iron-ajax>

    <app-toolbar>
      <div main-title>Load data using iron-scroll-threshold</div>
    </app-toolbar>

    <iron-scroll-threshold on-lower-threshold="loadMoreData" id="threshold">
      <iron-list id="list" items="[[categoriesJobs]]" as="person" scroll-target="threshold">
        <template>
          <div>
            <div class="personItem" tabindex$="[[tabIndex]]">
              <iron-image class="avatar" sizing="contain" src="[[person.picture.medium]]"></iron-image>
              <div class="pad">
                <div class="primary">[[person.name.first]] [[person.name.last]]</div>
                <address>
                  [[person.location.street]] [[person.city]] <br />
                  [[person.location.city]], [[person.location.state]] [[person.location.postcode]]
                </address>
              </div>
            </div>
          </div>
        </template>
      </iron-list>
    </iron-scroll-threshold>

  </template>

  <script>
    Polymer({
      is: 'job-category',
      attached: function () {
        this.companyDetail = [];
        this.categoriesJobs = [];
      },
      loadMoreData: function () {
        this.$.ajax.generateRequest();
      },
      categoriesLoaded: function (e) {
        var people = e.detail.response.results;
        this.categoriesJobs = people;
        this.$.threshold.clearTriggers();
      }
    });
  </script>

</dom-module>

问题在于iron-list, 来自docs https://elements.polymer-project.org/elements/iron-list:

iron-list 必须明确调整大小,或者将滚动委托给明确调整大小的父级......

在那里您可以找到不同的方法来做到这一点,但下面您可以看到一个有效的示例。在这个例子中我还修复了categoriesLoaded函数,因此它会加载更多数据,而不仅仅是替换旧数据。

JSBin 示例 http://jsbin.com/turecox/edit?html,console,output

我还在这里添加了代码:

<dom-module id="test-app">
  <template>

    <style>

      :host {

      }

      app-toolbar {
        height: 64px;
        background-color: grey;
      }

      iron-list {
        flex: 1 1 auto;
      }

      .container {
        height: calc(100vh - 64px);
        display: flex;
        flex-direction: column;
      }

    </style>

    <iron-ajax id="ajax" 
      url="https://randomuser.me/api/" 
      handle-as="json" 
      params='{"results": 20}'
      loading="{{loadingPeople}}"
      on-response="categoriesLoaded">
    </iron-ajax>

    <app-toolbar>
      <div main-title>Load data using iron-scroll-threshold</div>
    </app-toolbar>

    <div class="container">
      <iron-scroll-threshold on-lower-threshold="loadMoreData" id="threshold">
        <iron-list id="list" items="[[categoriesJobs]]" as="person" scroll-target="threshold">
          <template>
            <div>
              <div class="personItem" tabindex$="[[tabIndex]]">
                <iron-image class="avatar" sizing="contain" src="[[person.picture.medium]]"></iron-image>
                <div class="pad">
                  <div class="primary">[[person.name.first]] [[person.name.last]]</div>
                  <address>
                    [[person.location.street]] [[person.city]] <br />
                    [[person.location.city]], [[person.location.state]] [[person.location.postcode]]
                  </address>
                </div>
              </div>
            </div>
          </template>
        </iron-list>
      </iron-scroll-threshold>
    </div>

  </template>
  <script>
    Polymer({

      is: 'test-app',

      attached: function() {
        this.companyDetail = [];
        this.categoriesJobs = [];
      },

      loadMoreData: function () {
        console.log('load more data');
        this.$.ajax.generateRequest();
      },

      categoriesLoaded: function (e) {
        var self = this;
        var people = e.detail.response.results;
        people.forEach(function(element) {
          self.push('categoriesJobs', element);
        });
        this.$.threshold.clearTriggers();
      }

    });
  </script>
</dom-module>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

第一个列表滚动在聚合物中结束后,铁滚动阈值永远不会执行 的相关文章

随机推荐

  • Sparklyr 处理分类变量

    Sparklyr 处理分类变量 我来自 R 背景 习惯于在后端处理分类变量 作为因子 对于 Sparklyr 来说 使用起来相当混乱string indexer or onehotencoder 例如 我有许多变量在原始数据集中被编码为数值
  • R 中的 For 循环与 while 循环

    我在 R 工作时注意到一件奇怪的事情 当我有一个使用 for 循环和 while 循环实现的计算从 1 到 N 的平方的简单程序时 行为并不相同 在这种情况下我不关心矢量化或应用函数 fn1 lt function N for i in 1
  • pandas dataframe:loc 与查询性能

    我在 python 中有 2 个数据框 我想查询数据 DF1 4M 记录 x 3 列 这query功能好像多了 效率比loc功能 DF2 2K 记录 x 6 列 这loc功能似乎多了 效率比query功能 两个查询都返回一条记录 模拟是通过
  • 即使禁用 SSR,评估 SSR 模块也会出错 - svelte-kit

    我希望我的应用程序中的路线之一不要在服务器端渲染 这样做的方法是export const ssr false在模块脚本或设置中ssr false in svelte config js如中提到的精简文档 https kit svelte d
  • 在 null 上调用成员函数 helper()

    我正在尝试找出 codeigniter 但目前无法插入到我的数据库中 我一直在关注官方文档 成功从数据库中读取数据 我的错误完整 遇到未捕获的异常类型 错误 消息 在 null 上调用成员函数 helper 文件名 Library WebS
  • Android 录音

    我想知道如何使用 android 中的 AudioRecord 功能而不是 MediaRecorder 来录制我们的声音和播放 请给我示例代码或网址 提前致谢 我认为您可以从使用以下原型代码开始 import android media A
  • 难以理解 Android 应用程序中的复杂多线程

    我在理解应用程序中的多线程方面遇到了很大的问题 因此发现了一个错误 我已经检查过我认为所有的可能性 但仍然遇到各种 有时是意外的 错误 也许这里有人可以建议我 我应该做什么 在我的项目中 我使用两个外部库 图形视图 https github
  • 重定向到不同的控制器

    我在 IAuthorizationFilter 中有一些代码 它将用户重定向到登录页面 但我在更改所使用的控制器时遇到了问题 所以我可能会这样做 public void OnAuthorization AuthorizationContex
  • Redux 状态正在更新,无需分派任何操作

    我首先应该说这不是重复的这个问题 恰好有相同的标题 https stackoverflow com questions 48648736 redux state is being edited without dispatching any
  • 正则表达式: boost::xpressive 与 boost::regex

    我想用 C 做一些正则表达式 所以我查看了 interwebz 是的 我是 C 的初学者 中级 并发现这个答案 https stackoverflow com questions 181624 c what regex library sh
  • Angular SSR NgApexcharts SVG 未定义

    最初我在使用 Angular SSR 时遇到了这个包的问题 因为我在导入时遇到了这个错误Window is not defined 但是 你可以在server ts通过以下方式 const MockBrowser require mock
  • Python 重定向(有延迟)

    所以我在 Flask 上运行了这个 python 页面 它工作得很好 直到我想要重定向 app route last visit def check last watered templateData template text water
  • JVM 压缩 Oops 背后的技巧

    So I understand the compressed oops is enabled by default in HotSpot VM now It has support for this from Java SE 6u23 on
  • 具有右锚定静态面板的可变高度 FlowLayoutPanel

    Take a good look at this 我有一个顶部面板它停靠在Top我的形式 AutoSize True AutoSizeMode GrowOnly 在里面我有一个流程布局面板停靠到Fill AutoSize True Auto
  • 如何删除 UITabBarItem SelectionImage 填充?

    我通过 UITabBar 外观将 SelectionIndicatorImage 设置为可拉伸图像 以适应各种设备宽度 UIImage selectedImage UIImage imageNamed SelectedTab stretch
  • Netbeans 模块中的 JAXB

    当我尝试在 netbeans 模块中运行 JAXB 编组器时 它们似乎是一个问题 最初我以为这是节点实现 所以我花了几天时间重新组织一切 但我仍然收到奇怪的错误消息 javax xml bind JAXBException ClassCas
  • 替换for循环Python中的字符串元素

    我正在从文本文件中读取数据 因此每一行都是一个字符串列表 所有这些列表都在数据列表中 所以我的列表看起来像 data row1 row2 etc row1 str1 str2 etc 我正在尝试删除行列表中的字符串中出现的任何 或 符号 我
  • LZW解压算法

    我正在为必须实现 LZW 压缩 解压缩的作业编写一个程序 我为此使用以下算法 压缩 w NIL while read a character k if wk exists in the dictionary w wk else add wk
  • 如何将按钮字体设置为 Marlett

    我正在尝试将按钮的字体设置为系统的 Marlett 字体 然而 虽然我手动设置了font face 但使用了其他字体 此外 当我使用字体对话框为该按钮选择字体时 Marlett 未列出 为什么会这样呢 如何在 NET Windows 窗体控
  • 第一个列表滚动在聚合物中结束后,铁滚动阈值永远不会执行

    我已经使用以下方法完成了iron list and iron scroll threshold为了在聚合物中实现无限滚动 但问题是 loadMoreDatairon scroll threshold在聚合物中第一个列表滚动结束后永远不会执行