I have a server that works with the ETag header. The highway refers to the API for the first time: everything is fine, the response received and analysis. The second time: the trunk sends to the ETag server, in response receives NotModified. And Backbone is trying to analyze this answer, as a result of this we get a collection called reset.
Is there a way to reset the collection?
The method of adding options to add to the selection method will not work. Since I need to completely update the collection if I came to the server response.
var recommendCollection = Backbone.Collection.extend({
model : Event,
etag : null,
urlRoot : '/api/users',
initialize: function() {
this.etag = null;
},
parse: function(response) {
return response.data;
},
url : function () {
return (this.urlRoot + "/"+window.me.get('id')+ "/recommendation");
},
beforeSend : function (jqXHR, settings) {
jqXHR.setRequestHeader('if-none-match', this.etag);
},
complete : function (jqXHR, textStatus) {
if (jqXHR.status == 200 || jqXHR.status == 304) {
this.etag = jqXHR.getResponseHeader('ETag');
}
},
update : function () {
this.fetch({
beforeSend : this.beforeSend.bind(this),
complete : this.complete.bind(this),
data : {
cityId : window.me.get('cityId'),
}
});
}
source
share