1

为什么这段代码在 3 秒后没有改变?我究竟做错了什么?

<div data-bind="visible: isBusy()">
is busy
</div>

<div data-bind="visible: !isBusy()">
is not busy
</div>



var viewModel;
function AppViewModel() {
    var self = this;
    self.isBusy = ko.observable(true);
}

function isNotBusyAnymore() {
    viewModel.isBusy = ko.observable(true);
}

viewModel = new AppViewModel();
ko.applyBindings(viewModel);
setTimeout(isNotBusyAnymore, 3000);
4

1 回答 1

3

因为你一直在制作一个新的 observable ......而且你的函数总是将它设置为“true”

function isNotBusyAnymore() {
    viewModel.isBusy(false);
}
于 2012-05-23T03:18:19.077 回答