本文介绍了Dojo ConfirmDialog隐藏取消按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个dojo ConfirmDialog 如下:

I have a dojo ConfirmDialog as below:

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 动态如下:

Later on based on some condition, I am updating the ConfirmDialog dynamically as below:

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

在此阶段,取消没有任何功能按钮。我如何隐藏它?

At this stage, I do not have any function for the Cancel button. How do I hide it?

以下任何一项工作:

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

我可以将其禁用为:

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

但这看起来并不正确。我想完全隐藏取消按钮。

But that does not look correct. I want to hide the Cancel button completely.

我该怎么办?

推荐答案

cancelButton 按钮Dijit ,如果要隐藏/显示最后一个
,则必须通过简单地键入 this.myDialog.cancelButton.domNode
来访问它的domNode,使用隐藏/显示如下

The cancelButton is a button Dijit , if you want to hide / show this last ,you've to access it's domNode by smply typing this.myDialog.cancelButton.domNodeand use the dojo/dom-style to hide /show as below

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

请参阅以下工作摘要(使用外部按钮禁用启用)

see below working wnippet (disable enable using external button )

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隐藏取消按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 23:37