我正在使用knockout.js扩展应用程序,我希望动态显示文件上传。这是我的代码
function Search() {
var self = this;
//many different items set
self.totalSize = ko.observable(total);
self.uploadedSize = ko.observable(uploaded);
}
var uploadProgress;
var total = 100;
var uploaded = 0;
function runUploadProgress() {
uploadProgress = setInterval(function () {
callWebApi({
api: webapi.getUploadProgress,
data: null,
cache: false,
success: function (json) {
total = json.TotalBytes;
uploaded = json.TransferedBytes;
console.log(total + " - " + uploaded);
}
});
if (total == uploaded) {
stopUploadProgress();
}
}, 1000);
return true;
}
function stopUploadProgress() {
clearInterval(uploadProgress);
}
如何使用新值创建totalSize和uploadedSize可观察更新?如果我改变总值并上传它会改变observables中的值吗?
答案 0 :(得分:2)
创建observable后,您必须使用
更改可观察值searchInstance.totalSize(json.TotalBytes);
searchInstance.uploadedSzie(json.TransferedBytes);