gpt4 book ai didi

javascript - 可观察 knockout 更新

转载 作者:行者123 更新时间:2023-12-02 16:45:06 25 4
gpt4 key购买 nike

我正在使用 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可观察更新为新值?认为如果我更改总计的值并上传,它会更改可观察值中的值吗?

最佳答案

创建可观察值后,您必须使用以下命令更改可观察值

searchInstance.totalSize(json.TotalBytes);
searchInstance.uploadedSzie(json.TransferedBytes);

关于javascript - 可观察 knockout 更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27168510/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com