In the below code, I see that the collection initializer fires. I can also make the model initializer fire a different number of times based on server-side query mods that adjust the number of database hits, so I feel confident my fetch is hitting the server. However, I never get an alert after fetch. Can somebody please correct what is surely a mistake on my part?
$(function () {
Person = Backbone.Model.extend({
initialize: function () {
alert("Model Init");
}
});
PersonList = Backbone.Collection.extend({
model: Person,
url: '/Tfount_Email/Email/SOAInbox',
initialize: function () {
alert("Collections Init");
}
});
var personlist = new PersonList;
/*
personlist.fetch().complete(function () {
alert("done");
});
*/
personlist.fetch(
{
error: function () {
alert("error!!");
}
},
{
success: function () {
alert("no error");
}
}
);
});
Here you go.
Notes:
varkeyword forPersonandPersonList, you forgot that.fetch()returns a jQuery XHR object. You should bind thecompletecallback right with the call.fetch()accepts one options hash, not multiple ones.