主干 JS 分页
我一直在尝试使用 Rails 来使用主干 JS,并且非常喜欢它组织前端的方式。我已经实现了类似于这里的分页解决方案 https://gist.github.com/705733
我只是想知道什么集合的作用是以及它如何与分页结果一起工作。目前,当我从数据库中获取新对象时,它们似乎会覆盖当前集合中的内容。但是,我可以使用 {add: true} 添加到当前集合。这将使分页变得更加困难。那么缓存结果怎么样?我应该为每个页面创建一个新集合吗?
如果有人做过这件事或者知道如何去做,将会有很大的帮助。
I have been trying out backbone JS with rails and really like the way it organises the frontend. I have implemented a pagination solution similar to the one here https://gist.github.com/705733
I'm just wondering what the role of a collection is and how it should work with paginated results. Currently, it seems that when I fetch new objects from the database they override what's in the current collection. However, I could use {add: true} to add to current collection. This would then make pagination more difficult. And how about caching the result? Should i create a new collection for every page?
If anyone has done this or knows how to go about it would be of great help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的目标是查询&当请求页面时显示项目,您可以执行类似的操作(伪代码):
因此,您为每个页面保留一个集合。
如果您还需要迄今为止获取的所有项目的集合,只需保留一个 - 并在每次从服务器获取获取的项目时将其添加到其中。
If your objective is to query & display items when a page is requested, you could do something like (pseudocode):
So you keep a collection for each page.
If you also need a collection of all the items fetched so far, just keep one - and add fetched items to it every time you get them from the server.