【发布时间】:2014-07-03 05:17:19
【问题描述】:
下面关于 cmets 的解决方案。
问题:我的 loadMore() 方法会在每个容器的滚动条上执行。
含义:每次鼠标滚动父容器时都会执行 loadMore() (infinite-scroll-parent="true")
期望的结果:只有在infiniteScrollDistance满足其条件时才执行loadMore(),而不是我做的任何微小的滚动。
我的代码深受demo_basic 和demo_async 的启发。
我的应用是一个照片库。 我通过 ajax 调用加载照片,并将它们填充到缩略图指令转发器中。 我在控制器初始化时禁用 ng-Infinite-Scroll,并在回调成功时启用它。
<div class="thumbnails grid__item page--content">
<div id="gallery" class="unstyled-list"
infinite-scroll='loadMore()'
infinite-scroll-disabled='album.busy'
infinite-scroll-parent="true"
infinite-scroll-immediate-check="false"
infinite-scroll-distance='2'>
<my-photo-directive ng-repeat="photo in photos"></my-photo-directive>
</div>
</div>
我的咖啡代码没有任何意外。 它的逻辑不重要,因为如果我放置一个简单的console.log,问题仍然存在.....
$scope.album.busy = true
$scope.loadMore = ->
$scope.$apply ->
$scope.album.busy = true
console.log('loadMore() been executed here')
我的缩略图指令是相同的。毫不奇怪,当最后一张照片被填充到中继器上时,我启用了该组件。
app.directive 'myPhotoDirective', ['$window', ($window) ->
return {} =
....
link: (scope, element, attrs) ->
if scope.$last
scope.album.busy = false
我不知道我错过了什么或做错了什么。 我希望有人会在这里帮助我。
谢谢。
【问题讨论】:
-
如果你能在一个 plunker 中重新创建它会很有帮助,这样我们就可以看到错误在哪里。
-
It
s little complicated..... Its an app under dev, and I cannot expose it yet... Its the whole app, and probably some issue with my css and height calculation, that existing in my app, but will not in a clean code example.... Thats why I tried to expose maximum possible components of my app, hopefully that maybe someone already experienced this problem that in his ngInfiniteScroll implementation... **Ill 看看我能做什么伙计们** -
如果您可以在一个小型 plunker 应用程序中看到问题,那么您和我们都可以更轻松地进行调试。使用 chrome 开发工具查看报告的元素高度是否符合您的预期。
-
“cmets 下面的解决方案”是什么意思?
-
我评论了我的答案。这是一个让您感到舒适的直接链接 - stackoverflow.com/questions/23666712/…
标签: angularjs nginfinitescroll