我似乎无法iron-scroll-threshold
在iron-list
内使用app-header-layout
。
请注意,出于与某些第三方组件的兼容性原因,我仍然使用Polymer 1(1.11.3)。
这是一个简化的代码示例:
<app-location route="{{route}}"></app-location>
<app-route route="{{route}}" pattern="/app/:view" data="{{routeData}}" tail="{{subRoute}}"></app-route>
<app-route route="{{subRoute}}" pattern="/:id" data="{{idData}}" active="{{onDetailPage}}"></app-route>
<app-drawer-layout>
<app-drawer slot="drawer" swipe-open>
<app-toolbar class="navToolbar">
<a href="/app/foo" drawer-toggle>Menu Item 1</a>
</app-toolbar>
</app-drawer>
<app-header-layout>
<app-header class="mainHeader" condenses fixed effects="resize-title blend-background waterfall" slot="header">
<app-toolbar>
<paper-icon-button icon="menu" drawer-toggle></paper-icon-button>
<h4 condensed-title>Summary</h4>
</app-toolbar>
<app-toolbar class="tall">
<h1 main-title>Welcome</h1>
</app-toolbar>
</app-header>
<iron-pages selected="[[routeData.view]]" attr-for-selected="name" fallback-selection="home">
<time-line name="foo"></time-line>
<!-- other elements / pages -->
</iron-pages>
</app-header-layout>
</app-drawer-layout>
我要滚动的元素是:
<dom-module id="time-line">
<template>
<app-location route="{{route}}"></app-location>
<app-route route="{{route}}" pattern="/app/:view" data="{{routeData}}" tail="{{subRoute}}"></app-route>
<app-route route="{{subRoute}}" pattern="/:id" data="{{idData}}" active="{{onDetailPage}}"></app-route>
<iron-ajax id="loadData" attr="/api/foo" handle-as="json" on-response="dataLoaded"></iron-ajax>
<style is="custom-style"></style>
<iron-scroll-threshold id="threshold" on-lower-threshold="_loadMoreData">
<iron-list id="list" items="[[datas]]" as="data" scroll-target="threshold">
<template>
<div class="layout vertical">
<p>[[data]]</p>
</div>
</template>
</iron-list>
</iron-scroll-threshold>
</template>
<script>
Polymer({
is : "time-line",
properties: {
pagee: {
type: Number,
value: -1
},
datas: {
type: Array,
value: []
}
},
init: function() {
this.pagee = 0;
this.$.loadData.params = { "page" : this.pagee };
this.$.loadData.generateRequest();
},
dataLoaded: function(e) {
if (!this.datas) this.datas = [];
if (e.detail.response.length > 0) {
e.detail.response.forEach(function(element) {
this.push("datas", element);
}.bind(this));
this.$.threshold.clearTriggers();
}
},
_loadMoreData: function() {
this.pagee++;
this.$.loadData.params = { "page" : this.pagee };
this.$.loadData.generateRequest();
}
});
</script>
</dom-module>
答案 0 :(得分:0)
我只是偶然找到了解决方案(第{x 3}次{x}}):
<iron-scroll-threshold scroll-target="document" id="threshold" on-lower-threshold="_loadMoreData">
scroll-target="document"
是缺失的部分。
修改1
等等......我有ìron-list
和iron-scroll-threshold
两个元素,而且我已经设置了scroll-target="document"
。
现在效果是,当我滚动其中一个元素时,会为两个元素触发方法_loadMoreData
。怪异。
修改2
我破解了一个似乎“解决”问题的解决方法:
定义此功能:
function resetDocumentScrollers() {
var ist = document.querySelectorAll("iron-scroll-threshold");
[].forEach.call(ist, function(e) {
e.scrollTarget = null;
});
}
在每个元素的自定义init()
方法中,我打电话给:
resetDocumentScrollers();
this.$.threshold.scrollTarget = "document";
多么丑陋。