道场ConfirmDialog隐藏取消按钮(Dojo ConfirmDialog hiding ca

2019-09-30 02:18发布

我有一个道场ConfirmDialog如下:

this.myDialog = new ConfirmDialog({
                   title: "My Dialog",
                   content: "Do you want to continue?",
                   class: "confirmDialog",
                   closable: false
                });

// change button labels
this.myDialog.set("buttonOk","Yes");
this.myDialog.set("buttonCancel","No");

// register events
this.myDialog.on("execute", function() { 
                              self.continueSomething() 
                            });

后来根据一些条件,我正在更新ConfirmDialog动态如下:

this.myDialog.set("title", "New Title");
this.myDialog.set("content", "Its too late. Press ok to re-route.");
this.myDialog.set("buttonOk","Ok");

在这个阶段,我没有对任何的功能Cancel按钮。 如何隐藏呢?

以下工作无:

this.myDialog.cancelButton.hide();
//or
this.myDialog.cancelButton.set("display", "none");
//or 
this.myDialog.cancelButton.set("display", none);

我可以禁用它:

this.myDialog.cancelButton.set("disabled", true);

但是,这不完全正确。 我想隐藏的Cancel彻底按钮。

我该怎么做?

Answer 1:

cancelButton是一个button Dijit ,如果你想隐藏/显示此最后,你访问它是由れ打字smply this.myDialog.cancelButton.domNode和使用dojo/dom-style隐藏/如下显示

let cancelBtnDom = this.myDialog.cancelButton.domNode;
domStyle.set(cancelBtnDom, 'display', 'none');

见下文的工作wnippet(禁用启用使用外部按钮)

 require(["dijit/ConfirmDialog", "dojo/dom-style", "dojo/domReady!"], function(ConfirmDialog, domStyle){ myDialog = new ConfirmDialog({ title: "My ConfirmDialog", content: "Test content.", style: "width: 300px" },"dialog"); let cancelBtn = myDialog.cancelButton.domNode; let switchBtn = document.getElementById("switch"); switchBtn.addEventListener("click",function(){ let display = domStyle.get(cancelBtn, "display") !== "none" ? "none" : ""; console.log(display); domStyle.set(myDialog.cancelButton.domNode, 'display', display); }); }); 
 <script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script> <link href="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dijit/themes/claro/claro.css" rel="stylesheet" /> <body class="claro"> <div class="dialog"></div> <button onclick="myDialog.show();">show</button> <button id="switch" >enable/Disable cancel button</button> </body> 



文章来源: Dojo ConfirmDialog hiding cancel button