Backbone.PageableCollection 定义的搜索
Backbone.PageableCollection defined search
我正在尝试将Backbone.PageableCollection与附加的queryParams一起使用,但不起作用。
我已经尝试了 _.extend 查询参数和状态,但产生了一个值=值查询结果。例如,如果我将 {gender: 'male'} 添加到查询参数并声明,则查询字符串是 ...?男=男... 我需要知道如何在服务器端解释这一点。 我尝试使用下划线的反转来获得值=键对,但这没有帮助。
咖啡脚本:
class Entities.UserCollection extends Backbone.PageableCollection
initialize: (searchCriteriaModel) ->
_.extend(@queryParams, searchCriteriaModel)
_.extend(@state, searchCriteriaModel)
model: Entities.UserModel
url: '/api/ra/users'
state:
firstPage: 1
currentPage: 1
pageSize: 6
totalRecords: 200
任何帮助将不胜感激
我找到了答案。 我无法在"初始化"期间应用"状态"数据。 我只是在集合获取之前添加了 _.extend 。 我还发现我可以用同样的方式操纵状态。
更新的代码:
class Entities.UserModel extends Backbone.Model
class Entities.UserCollection extends Backbone.PageableCollection
model: Entities.UserModel
url: '/api/ra/users'
state:
firstPage: 1
currentPage: 1
queryParams:
currentPage: "current_page"
pageSize: "page_size"
offset: () -> (@state.currentPage-1) * @state.pageSize
API =
getUsers: (state, searchCriteriaModel) ->
items = new Entities.UserCollection
_.extend items.state, state
_.extend items.queryParams, searchCriteriaModel
items.fetch
async: false
reset: true
success: (collection, response, options) ->
console.log "success:", collection
error: (collection, response, options) ->
console.log "error:", collection
items
相关文章:
- 谷歌水印未显示在自定义搜索框中
- 如何让typeahead在我的搜索栏中填充自定义参数
- 从谷歌自定义搜索返回随机帖子
- 为自定义网站创建JavaScript搜索框,创建显示搜索结果的弹出窗口
- 在javascript中调用自定义谷歌搜索标签时出现问题
- jqgridnavgrid在搜索按钮和自定义按钮之后添加按钮
- 是Google自定义搜索API的客户端请求数量有限
- 如何从谷歌自定义搜索下载搜索结果
- 如何将从谷歌自定义搜索API获取的数据放入复选框列表
- 可能带有iframes/html5的自定义搜索页面
- 谷歌自定义搜索参考部门
- 如何使用javascript为谷歌自定义搜索添加价值
- 谷歌自定义搜索结果通过代理显示错误
- 在搜索类型定义时,何时使用环境光
- 如何定义搜索词框来搜索用户'使用Twitter流API和meter.js的特定时间线
- 隐藏Google自定义搜索元素API 2.0的搜索引擎ID
- 如何在Angular 1.3.6上创建一个自定义过滤器来搜索嵌套数组
- 谷歌新闻 API 自定义搜索
- 从我的网站中删除 Google 自定义搜索
- 搜索/将自定义标记替换为 javascript 正则表达式