我正在尝试覆盖 Backbonesync
函数以监听progress
事件。但是,xhr.upload
未定义,因此下面的代码不起作用。有任何想法吗?
var Model = Backbone.Model.extend({
...
sync: function(method, model, options) {
options.beforeSend = function(xhr) {
xhr.upload.addEventListener("progress", function(event) {
if (event.lengthComputable) {
var percentComplete = event.loaded/event.total;
console.log(percentComplete);
}
}, false);
}
return Backbone.sync(method, model, options);
},
...
});