2015-05-03 9 views
0

您好我有一個簡單的應用程序列表的帖子,我奮力沿着添加使用鐵路由器流星分頁一個簡單的分頁:使用Iron路由器和Pagination.collection()爲流星應用設置簡單分頁?

if (Meteor.isClient) { 
    Template.index.helpers({ 

     posts: function() { 
      return Posts.find({}, {sort: {voteResult: -1}}); 
     }, 
} 
https://github.com/egtann/meteor-pagination

我在index.js以下

並因此表現出我使用{{#each posts}}像這樣的職位在我的index.html

 <template name="index"> 
      <ul> 
      {{#each posts}} 
       <li> 
        {{text}} 
       </li> 
      {{/each}}  
      </ul> 
<!-- pagination BOOTSTRAP CSS --> 
    <!-- <div class="text-center"> 
      <ul class="pagination_bis"> 
       <li> 
       <a href="#" aria-label="Previous"> 
        <span aria-hidden="true">&laquo;</span> 
       </a> 
       </li> 
       <li class="active_bis"><a href="#">1</a></li> 
       <li><a href="#">2</a></li> 
       <li><a href="#">3</a></li> 
       <li><a href="#">4</a></li> 
       <li><a href="#">5</a></li> 
       <li> 
       <a href="#" aria-label="Next"> 
        <span aria-hidden="true">&raquo;</span> 
       </a> 
       </li> 
      </ul> 
     </div> --> 
     </template> 

這裏是我的route.js

Router.configure({ 
    loadingTemplate: 'loading', 
    notFoundTemplate: 'notFound', 
    layoutTemplate: 'layout' 
}); 

Router.route('/', function() { 
    this.render('index'); 
}); 

我的問題:

  • 如何在routes.js(鐵路由器)進行簡單的分頁定義我的路線?
  • 如何在我的index.js中使用Meteor分頁幫助(上面提供的鏈接)使用該路由,以便僅基於perPage基礎返回有限數量的Posts?
  • 如何將此邏輯連接到視圖(index.html)?

我試圖按照上面提供的鏈接的例子,但我很困惑,他們使用的流星的版本已被棄用。不用說,我是流星的新手,每一個輸入都是真正的讚賞。爲了您的信息,應用程序事件工作正常,我設法保存和刪除帖子,爲測試分頁創建了超過30個帖子。謝謝。

回答

1

我不會使用不再維護的軟件包(最近一次提交的文章是egtann:meteor-pagination是2年前)。

而是簡單地嘗試alethes:pagesGitHub project)。似乎也有很好的文檔記錄。

至於路由器。你可能必須使用URL參數(如果你想通過URL直接訪問特定頁面 - 例如/posts/5/爲第5頁):

Router.route('/posts/:page', function() { 
    var pageId = this.params.page; 
    ... 
}); 
+0

你能告訴我/告訴我如何在html中設置':page'等於postId,以便它呈現正確的路線/ posts /:page? – Antoine

+0

嗯不幸的是我的主要域名。我想你可能需要一個控制器(在鐵路路由器上搜索它)。有一個人正在做這樣的事情:https://crater.io/top/40 - 你可以檢查源代碼並搜索'/ top /:'來查找路由聲明以及它們如何解決它。 –

+0

謝謝彼得的幫助 – Antoine

相關問題