I\'m new in Backbone. So I\'m trying to fetch data from REST service.
this is my simple code:
$(function () {
var Entity = Backbone.Model.extend
I think you are on the right way. But because Backbone.Collection.fetch()
is async, you should check value of entityList.models
not right after the method call, but in success
callback of fetch.
That is, this code will say that models list is empty:
entityList.fetch();
console.log(entityList.models); // => 0 (collection being fetched)
while this code will print number of models in the collection when it have been populated:
entityList.fetch({success: function(){
console.log(entityList.models); // => 2 (collection have been populated)
}});