开发者

Backbone.js appending more models to collection

开发者 https://www.devze.com 2023-04-07 16:08 出处:网络
I have a following code that fetches data from the server and add to the collection. // common function for adding more repos to the collection

I have a following code that fetches data from the server and add to the collection.

// common function for adding more repos to the collection
var repos_fetch = function() {
  repos.fetch({
    add: true,
    data: {limit:curr_limit, offset:(curr_offset*curr_limit)},
    success:function() {
      curr_offset++;
      console.log(repos.length);
    }       
  });       
};

each time I call the function 开发者_如何学Python"repos_fetch", the data is retrieved from the server and added to the collection "repos".

My problem is that I want to APPEND to the collection, instead of REPLACING. So I put the option "add: true" there.

But below function looks like it's keep replacing the data in collection.

What's even strange is that if I remove the line "curr_offset++;" then the data gets appended!. "curr_offset" just increments, so I get different sets of data.

What's going on here?

0

精彩评论

暂无评论...
验证码 换一张
取 消