发生某些事件后,如何在KO JS中禁用按钮?

发布于 2025-02-12 17:52:06 字数 648 浏览 0 评论 0原文

在页面上加载表之后,我正在尝试启用禁用按钮。

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>

结果,我只能禁用此按钮,并且未启用它。试图调试和输入 pricingtablerenderedhandler uploadpdfbuttonisenabled 成为True,但该按钮仍然禁用

I'm trying to enable disabled button after I load a table on the page.

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

        //some other irrelevant logic
}

.cshtml file

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

As a result, I only get this button disabled and it is not enabled. Tried to debug and the pricingTableRenderedHandler is entered, uploadPdfButtonIsEnabled becomes true but the button is still disabled

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

給妳壹絲溫柔 2025-02-19 17:52:06

您必须使用可观察的敲除绑定才能自动更新:

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

You have to use an observable for the knockout binding to be able to update automatically:

// 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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文