2017-04-25 183 views
0

我正在使用YUI Paginator用于分页的API,我需要显示屏幕上的总页数。我看到在API中有一个函数getTotalPages(),但我不确定如何使用它,没有足够的文档。另外看过其他文档后,我尝试使用{totalPages},但没有奏效。 有人能帮我解决这个问题吗?提前致谢!! 以下是我正在使用的代码片段。请参考模板对象从配置:如何显示YUI Paginator中的页面总数?

config = { 
       rowsPerPage: 100, 

       template : 
        '<p class="klass">' + 

         '<label>Total pages: {totalPages}</label>'+ 
         '<label>Page size: {RowsPerPageDropdown}</label>'+ 
        '</p>', 
       rowsPerPageDropdownClass : "yui-pg-rpp-options", 
       rowsPerPageOptions : [ 
            { value : 100 , text : "100" }, 
            { value : 250 , text : "250" }, 
            { value : 500 , text : "500" }, 
            { value : 1000 , text : "1000" }, 
            { value : tstMap[tabName].length , text : "All" } 
           ], 
      };                
var myPaginator = new YAHOO.widget.Paginator(config); 

回答

1

的分页程序实用,可以显示一个项目或一组取决于你想在同一时间显示的项目数量的项目。

Paginator的主要功能包含在paginator-core中,并混合到paginator中以允许paginator添加额外功能,同时保持核心功能不变。这允许paginator-core保持可用于以后的使用或孤立使用,如果它是唯一您需要的部分。

由于Paginator可能包含大量接口,因此Paginator不包含任何可以使用的UI。但是,Paginator可以在任何基于Based的模块(如Widget)中使用,方法是在Paginator中扩展所需的类并混合。这显示在以下示例中:

YUI().use('paginator-url', 'widget', function (Y){ 
      var MyPaginator = Y.Base.create('my-paginator', Y.Widget, [Y.Paginator], { 

       renderUI: function() { 
        var numbers = '', 
         i, numberOfPages = this.get('totalPages'); 

        for (i = 1; i <= numberOfPages; i++) { 
         // use paginator-url's formatUrl method 
         numbers += '<a href="' + this.formatUrl(i) + '">' + i + '</a>'; 
        } 

        this.get('boundingBox').append(numbers); 
       }, 

       bindUI: function() { 
        this.get('boundingBox').delegate('click', function (e) { 
         // let's not go to the page, just update internally 
         e.preventDefault(); 
         this.set('page', parseInt(e.currentTarget.getContent(), 10)); 
        }, 'a', this); 

        this.after('pageChange', function (e) { 
         // mark the link selected when it's the page being displayed 
         var bb = this.get('boundingBox'), 
          activeClass = 'selected'; 

         bb.all('a').removeClass(activeClass).item(e.newVal).addClass(activeClass); 
        }); 
       } 

      }); 

      var myPg = new MyPaginator({ 
          totalItems: 100, 
          pageUrl: '?pg={page}' 
         }); 

      myPg.render(); 
     }); 
相关问题