为什么knockoutjs没有正确绑定?

时间:2012-05-23 03:12:26

标签: javascript knockout.js

3秒后为什么this code没有变化?我做错了什么?

<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);

1 个答案:

答案 0 :(得分:3)

因为你不断制作新的可观察物......而且你的功能总是将它设置为“真实”

function isNotBusyAnymore() {
    viewModel.isBusy(false);
}