0

我正在编写一个需要分页的骨干集合。所以这是我的代码

define([
  'underscore',
  'backbone',
  'models/object',
  'backbone_paginate'

], function(_, Backbone, Object){
   "use strict";
  var myCollection= Backbone.Paginator.clientPager.extend({


    model: Object,


      paginator_core: {
          // the type of the request (GET by default)
          type: 'GET',

          // the type of reply (jsonp by default)
          dataType: 'json',

          // the URL (or base URL) for the service
          url: location.protocol + '//' + location.host+'/address'
      },

      paginator_ui: {
          // the lowest page index your API allows to be accessed
          firstPage: 1,

          // which page should the paginator start from
          // (also, the actual page the paginator is on)
          currentPage: 1,

          // how many items per page should be shown
          perPage: 3,

          // a default number of total pages to query in case the API or
          // service you are using does not support providing the total
          // number of pages for us.
          // 10 as a default in case your service doesn't return the total
          totalPages: 10,

          pagesInRange: 3
      },

      server_api: {
           '$top': function() {
               return this.totalPages * this.perPage; },

          },

       parse:function(dat){
      return dat.items;
    }


     });
  return new myCollection();
});

我的观点是这样的:

define([
  'jquery',
  'underscore',
  'backbone',
   'collections/addressLists',
     'models/object',
     'views/shared_object_item',

], function($, _, Backbone, AddressLists,Address,Shared_object_item){
  "use strict";

  var AppView = Backbone.View.extend({
    events: {

    },



    initialize: function() {

      _.bindAll(this,'render','updateData','showMoreData','showAllData');              this.collection=AddressLists;
     this.collection.bind('reset',this.render);
       this.collection.fetch();


    },

     el:$('div')[0],
     render: function() {

       var that=this;
      $('.innerContainer').bind('scroll',function(){
         if($(this)[0].scrollHeight-$(this).scrollTop()==$(this).outerHeight()){
           that.showMoreData();
          }
      });
        this.updateData();
       },

    updateData:function(){
      var that=this,collection;
      $('.innerItem').empty();

      _.each(this.collection.models,function(model){
         $('.innerItem').append(new Shared_object_item({parent:that,collection:that.collection,model:model}).render().el);
      });

    },
      showMoreData:function(){

this.collection.requestNextPage();

      },
   });
  return AppView;
});

现在在我看来,我正在调用:fetch();

在获取成功后,我试图调用 this.collection.requestNextPage();

它在 fetch() 之前工作正常,但是一旦它到达 requestNextPage 函数(位于 showMoreData() 函数中),它就会抛出一个错误,指出 requestNextPage() 不是一个函数。

我不知道我在哪里出错了..

4

1 回答 1

0

Backbone.Paginator 文档 requestNextPage(options)是一种方便的方法Paginator.requestPager,但您正在扩展Paginator.clientPager. 看起来你需要使用nextPage().

于 2012-12-20T01:46:30.290 回答