【问题标题】:Dojo : how to set to disable new buttonDojo:如何设置禁用新按钮
【发布时间】:2013-07-19 03:50:10
【问题描述】:

您好,我无法将新按钮设置为禁用。 我正在使用 Dojo 1.8

在下面查看我的代码:-

require(["dojo/parser", "dijit/layout/BorderContainer",
"dijit/form/Button","dojo/on","dijit/form/Select",
"dojo/store/Memory", "dojo/request","dojo/domReady!"
],
function(parser, BorderContainer, Button, on, Select, Memory, request)
{

var btn4 = new Button // Button, not button
({
    label: "Number of cards",
    this.set("disabled", false) // This code that disables the button
    },"btn4"); 
btn4.startup();
})

我在 Dojo 或 google 中找不到帮助。

【问题讨论】:

    标签: button dojo


    【解决方案1】:

    在 Dojo 中,许多事情与您所期望的不同。

    按钮有方法setDisabled:

    btn4.setDisabled(true) // disable
    btn4.setDisabled(false) // enable
    

    【讨论】:

    • 令人惊讶的是,你是对的。我可以使用 button.set('disabled', true) 禁用按钮,但无法使用 button.set('disabled', false) 重新启用它——它似乎在某处投射了 false => null。 button.setDisabled(false) 方法有效。我认为这是一个道场错误。
    【解决方案2】:

    首先,尝试在 dijit 的参数列表中调用 this.set() 是没有意义的,因为 dijit 尚未创建。其次,dijit 的第一个参数始终是具有键/值对的标准 javascript 对象。试图在对象声明的中间插入函数调用只是代码本身的语法错误。

    最后,完全没有必要尝试使用 dijit 的 setter。只需将参数列表中的disabled: true 设置为Button dijit。

    var btn4 = new Button({
        label: "Number of cards",
        disabled: true,
    }, "btn4"); 
    

    看到这个Fiddle

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多