Backbone.js的集合让瓦尔 [英] backbone.js collection get vars

查看:109
本文介绍了Backbone.js的集合让瓦尔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎是一个明显的例子,但我莫名其妙地失踪了......

This seems like an obvious one, but I'm somehow missing it...

你如何发送带有一个Backbone.js的集合一起选择取()?

How do you send options along with a backbone.js collection fetch()?

或者,从更广泛的角度:我在服务器上的大型数据集,在这种情况下的消息,我想通过一个集合进行访问。眼看因为可能会有数千我不想简单地获取和存储所有这些一次的消息,所以我的采集必须至少了解限制和偏移。且不说查询过滤或排序名单。

Or, from a broader point of view: I have a large dataset on the server, messages in this case, that I want to make accessible through a collection. Seeing as there could be thousands of messages I don't want to simply fetch and store all of them at once, so my collection would have to at least understand limits and offsets. Not to mention querying filtered or sorted lists.

是骨干集甚至处理这种方式?

Is a backbone collection even the way to handle this?

干杯

推荐答案

我已经和骨干几天,现在搞乱,我不得不几乎立即处理这个问题,我看着这个解决方案,但我发现它笨重。阅读一些骨干文件之后,我发现你其实可以抓取()方法中重写任何 jQuery.ajax 选项。因此,例如

I've been messing with Backbone for a couple days now and I had to deal with this problem almost immediately and I looked at this solution, but I found it clunky. After reading some more backbone documentation I discovered you can actually override any of the jQuery.ajax options within the fetch() method. So for example

Posts = Backbone.Collections.extend({
  model: Post,
  url: '/posts'
});

现在,当你要调用只取送它你希望的任何参数。例如。

Now when you want to call fetch just send it whatever parameters you wish. e.g.

var posts = new Posts();
posts.fetch({ data: { page: 3, pagesize: 10, sort: 'asc' } });

这将产生以下要求:

http://yourdomain/posts?page=3&pagesize=10&sort=asc

不管怎样,我知道你已经接受了答案,但希望这会帮助别人。

Anyway, I know you've already accepted an answer, but hopefully this will help someone.

这篇关于Backbone.js的集合让瓦尔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆