knockout.js 如何在某些事件发生后禁用KO JS中的按钮?

sf6xfgos  于 2022-11-10  发布在  其他
关注(0)|答案(1)|浏览(148)

在页面上加载表后,我试图启用禁用的按钮。

self.uploadPdfButtonIsEnabled = false;
self.pricingTableRenderedHandler = function (data, stateName) {
        self.uploadPdfButtonIsEnabled = true;

        //some other irrelevant logic
}

.cshtml文件

<button class="button button--primary" id="uploadPdfsButton" data-bind="click: $root.openPdfUpload, enable: uploadPdfButtonIsEnabled">
      <span class="button__text">Upload PDF</span>
 </button>

因此,我只禁用了此按钮,但它未启用。尝试调试并输入了pricingTableRenderedHandleruploadPdfButtonIsEnabled变为true,但此按钮仍处于禁用状态

ccrfmcuu

ccrfmcuu1#

您必须使用可观察项,以使敲除绑定能够自动更新:

// Pass the initial value: `false`
self.uploadPdfButtonIsEnabled = ko.observable(false);
self.pricingTableRenderedHandler = function (data, stateName) {
  // Update by calling with the new value: `true`
  self.uploadPdfButtonIsEnabled(true);
}

相关问题