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({
url: function() {
return 'http://localhost:8080/rest/entity/'+this.id;
}
});
var EntityList = Backbone.Collection.extend({
model: Entity,
url: 'http://localhost:8080/rest/entity'
});
var entityList = new EntityList();
entityList.fetch();
});
my rest service returns next JSON:
[{"id":1387,
"version":3,
"entityName":"entity01",
"entityLabel":"Entity01",
"entityPluralLabel":"Entity01",
"attributes":
[{"id":1425,
"slot":"D001",
"version":0,
"attributeName":"dfield",
"attributeType":
{"id":7,
"description":"Date",
"attributeType":"date",
"databaseType":"DATE"
},
"options":[],
"order":2,
"attributeLabel":"dField",
"checked":null
},
{"id":1424,
"slot":"S001",
"version":0,
"attributeName":"txfield",
"attributeType":
{"id":1,
"description":"Textbox",
"attributeType":"textbox",
"databaseType":"STRING"
},
"options":[],
"order":1,
"attributeLabel":"txField",
"checked":null
}
]
},
{"id":1426,
"version":3,
"entityName":"entity02",
"entityLabel":"Entity02",
"entityPluralLabel":"Entity02",
"attributes":
[{"id":1464,
"slot":"D001",
"version":0,
"attributeName":"dfield",
"attributeType":
{"id":7,
"description":"Date",
"attributeType":"date",
"databaseType":"DATE"
},
"options":[],
"order":2,
"attributeLabel":"dField",
"checked":null
}
]
}
]
In debugger I see that request was sent to REST service and response was recieved, how can I see if entityList collection is populated with recieved data or not? In debugger entityList.models is empty after entityList.fetch();
Am I on right way or somthing is wrong with my code?
question from:
https://stackoverflow.com/questions/7259712/backbone-js-rest-collection-is-not-populated-after-fetch