Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Meteor “加载更多”按钮使页面跳转到顶部_Meteor - Fatal编程技术网

Meteor “加载更多”按钮使页面跳转到顶部

Meteor “加载更多”按钮使页面跳转到顶部,meteor,Meteor,我希望当用户单击“加载更多”时,我的页面不会跳到顶部。如本例所示。下面是所需效果的一个示例 我用的是熨斗:路由器 template(name="articlesList") .articles each articles +articleItem .show-more-news-container if articlesReady if nextPath a(id="show-more-news-link", class="sho

我希望当用户单击“加载更多”时,我的页面不会跳到顶部。如本例所示。下面是所需效果的一个示例

我用的是熨斗:路由器

template(name="articlesList")
  .articles
    each articles
      +articleItem

  .show-more-news-container
    if articlesReady
      if nextPath
        a(id="show-more-news-link", class="show-more-news-link") Show More News
    else
      +spinner


Template.articlesList.events
  'click #show-more-news-link': (e,t)->
    e.preventDefault()
    @loadMoreHandler()

Router.route '/news/top/:articlesLimit?',
 name: 'articlesListTop'
 template: 'articlesList'
 controller: 'ArticlesListController'

@ArticlesListController = RouteController.extend({
  template: 'articlesList'
  increment: 4
  articlesLimit: ->
    parseInt(this.params.articlesLimit) or @increment
  subscriptions: ->
    @articlesSub = Meteor.subscribe 'articlesData', @articlesLimit()
  articles: ->
   Posts.find {}, { sort: {submitted: -1} }
  data: ->
    hasMoreArticles = @articles().count() == @articlesLimit()
    nextPath = @router.path('articlesListTop', {articlesLimit: @articlesLimit() + @increment})

    return {
      articles: @articles()
      articlesReady: @articlesSub.ready()
      nextPath: if hasMoreArticles then nextPath else null
      loadMoreHandler: ->
       Router.go(nextPath)
    }
})

这段代码成功地使我的加载按钮更有效,但它也使我的页面在每次单击时跳转到顶部。有人知道是什么导致了这种行为吗?

我发现了问题。我还有另外一个waitOn函数,它在RouterController中定义了用户订阅,这导致页面向上跳转,因为每次它都会进入加载模板几纳秒