Javascript 淘汰赛和比赛时间

Javascript 淘汰赛和比赛时间,javascript,jquery,knockout.js,Javascript,Jquery,Knockout.js,我有一个计算函数,通知按钮是否应该禁用。 我还订阅了这个计算函数,它更新了另一个可观察对象。更新此可观察对象时,它将运行自定义绑定 问题是subscribe()在按钮被禁用之前正在运行。我希望先运行计算函数,然后启用/禁用按钮,最后运行订阅 这可能吗?setTimeout()不是一个好选项 this.enableButton = ko.computed(function() { return true or false }); this.enableButton.subscribe(functi

我有一个计算函数,通知按钮是否应该禁用。 我还订阅了这个计算函数,它更新了另一个可观察对象。更新此可观察对象时,它将运行自定义绑定

问题是subscribe()在按钮被禁用之前正在运行。我希望先运行计算函数,然后启用/禁用按钮,最后运行订阅

这可能吗?setTimeout()不是一个好选项

this.enableButton = ko.computed(function() { return true or false });
this.enableButton.subscribe(function() { myself.triggerBinding(true) });
html:


如果我理解正确,我希望这有助于:


谢谢!正是我想要的:D
<button data-bind="enable: enableButton" />
var viewModel = {
    buttonIsEnabled : ko.observable(true)
};

viewModel.enableButton = ko.computed({
    read : function () {
        log("read enableButton");
        return this.buttonIsEnabled();
    },
    write : function (isEnabled) {
        log("write enableButton");
        this.buttonIsEnabled(isEnabled);         
    },
    owner : viewModel    
});

viewModel.otherObservable = ko.computed({
    read : function(){
        log("read otherObservable");
        return this.buttonIsEnabled();
    },
    write : function () {
        log("write otherObservable");
    },
    owner : viewModel
});

viewModel.otherObservable.subscribe(function(){
    log("run subscription");
    log("----------------");
});

function log(message){
    $("#log").append(message + "\n");
}
ko.applyBindings(viewModel);