admin管理员组

文章数量:1293520

So I understand we can do something like this:

Collection.fetch({success: function() { bla.. } } )

But say I wanted something like this:

Collection.fetch( { success: function () { if (condition) { this.fetch() } }})

The problem is, the second time I call fetch (the one in bold), it won't have the success function associated with it. What I want to do is: Call fetch until that condition bees true...that condition is based on the data (result) of the previous fetch.

Anyone?

So I understand we can do something like this:

Collection.fetch({success: function() { bla.. } } )

But say I wanted something like this:

Collection.fetch( { success: function () { if (condition) { this.fetch() } }})

The problem is, the second time I call fetch (the one in bold), it won't have the success function associated with it. What I want to do is: Call fetch until that condition bees true...that condition is based on the data (result) of the previous fetch.

Anyone?

Share asked Jan 12, 2012 at 3:26 UserXYZUserXYZ 2233 silver badges14 bronze badges 1
  • 1 possible duplicate of backbone.js collection - Calling fetch repeatedly to get all "pages" from server – kubetz Commented Jan 12, 2012 at 3:40
Add a ment  | 

1 Answer 1

Reset to default 9

You could declare the function outside of the parameter like so, this way you can reference it later.

var collection = new Backbone.Collection();
var success = function(){
    if(condition){
        collection.fetch({success : success});
    }
 };
 collection.fetch({success : success});

本文标签: