backbone.js cache collections and refresh

后端 未结 3 1643
粉色の甜心
粉色の甜心 2021-02-10 09:06

I have a collection that can potentially contain thousands of models. I have a view that displays a table with 50 rows for each page.

Now I want to be able to cache my

3条回答
  •  情歌与酒
    2021-02-10 09:43

    Backbone.Collection.fetch has an option {add:true} which will add models into a collection instead of replacing the contents.

    myCollection.fetch({add:true})
    

    So, in your first scenario, the items from page2 will get added to the collection.

    As far as your 2nd scenario, there's currently no built in way to do that.

    According to Jeremy that's something you're supposed to do in your App, and not part of Backbone.

    Backbone seems to have a number of issues when being used for collaborative apps where another user might be updating models which you have client side. I get the feeling that Jeremy seems to focus on single-user applications, and the above ticket discussion exemplifies that.

    In your case, the simplest way to handle your second scenario is to iterate over your collection and call fetch() on each model. But, that's not very good for performance.

    For a better way to do it, I think you're going to have to override collection._add, and go down the line dalyons did on this pull request.

提交回复
热议问题