骨干分页

时间:2013-12-01 15:27:46

标签: rest backbone.js pagination paginator

任何人都可以向我解释这个backbone.paginator示例是如何工作的吗?

https://github.com/backbone-paginator/backbone.paginator/blob/master/examples/request-paging/collections/PaginatedCollection.js

我看到可以使用以下网址访问后端:

paginator_core: {
  type: 'GET',
  dataType: 'jsonp',
  url: 'https://api.github.com/repos/twitter/bootstrap/issues?'
},

但是这个例子是什么/在哪里传递了从后端检索的页码和主题数量?我的后端可通过以下restfull url访问:我无法弄清楚下一页的详细信息如何插入上面的URL ...

www.test.com/getItems/{query}/{from}/{size}

这是否由paginator插件自动插入?

1 个答案:

答案 0 :(得分:0)

只需检查fetch方法的内部实现

 // map params except directions
      var queryParams = this.mode == "client" ?
        _pick(this.queryParams, "sortKey", "order") :
        _omit(_pick(this.queryParams, _keys(PageableProto.queryParams)),
              "directions");

      var i, kvp, k, v, kvps = _pairs(queryParams), thisCopy = _clone(this);
      for (i = 0; i < kvps.length; i++) {
        kvp = kvps[i], k = kvp[0], v = kvp[1];
        v = _isFunction(v) ? v.call(thisCopy) : v;
        if (state[k] != null && v != null) {
          data[v] = state[k];
        }
      }

请求基于

创建
queryParams: {
  currentPage: "page",
  pageSize: "per_page",
  totalPages: "total_pages",
  totalRecords: "total_entries",
  sortKey: "sort_by",
  order: "order",
  directions: {
    "-1": "asc",
    "1": "desc"
  }
},

property - 因此当前集合状态mapps over queryParams设置为世代url