你可以这样做:
var fetch = Backbone.Collection.prototype.fetch;
Backbone.Collection.prototype.fetch = function (options) {
options = options ? _.clone(options) : {};
var success = options.success;
options.success = function (collection, resp, options) {
collection.xhrObj = resp;
if (success) success(collection, resp, options);
};
var error = options.error;
options.error = function (collection, resp, options) {
collection.xhrObj = void 0; // or whatever you want
if (error) error(collection, resp, options);
};
fetch.call(this, options);
};
之后,如果 fetch 调用成功,您可以在您的集合中找到服务器响应。