Reputation: 1877
Tried the following:
var collectionList = users.fetch();
alert(collectionList);
This returns null despite there being models in it.
Update - this worked for me:
users.fetch({
success: function() {
console.log(users.toJSON());
},
error: function() {
// something is wrong..
}
});
Upvotes: 0
Views: 90
Reputation: 23893
This one also can
var that = this;
users.fetch({
success: function(collection, response) {
console.log(that.collection.toJSON());
},
error: function() {
// something is wrong..
}
});
Upvotes: 0
Reputation: 2520
users.fetch({
success: function(response) {
_.each(response.models, function(model) {
//Do something with the model here
});
}
});
Upvotes: 1
Reputation: 1877
Fetch is an async method, so is empty upon being called, after you specify success and error you should be able to then list your models.
users.fetch({
success: function() {
console.log(users.toJSON());
},
error: function() {
// something is wrong..
}
});
Upvotes: 0
Reputation: 76219
users.fetch().then(function () {
console.log(users.toJSON());
});
http://backbonejs.org/#Collection-fetch
Upvotes: 0