[英]Bootstrap's modal - click on cancel button - trigger `close()` or `dismiss()`?
Bootstrap's modal provides two methods to hide the dialog: Bootstrap的模式提供了两种隐藏对话框的方法:
close(result) (Type: function) - Can be used to close a modal, passing a result. close(result)(Type:function)-可用于关闭模式,并传递结果。
dismiss(reason) (Type: function) - Can be used to dismiss a modal, passing a reason. dismiss(reason)(Type:function)-可用于通过原因而消除模态。
Is my understanding correct that I should use close
when a user clicks on the OK
button on the dialog, and dismiss
when the user clicks on the cancel
button? 我的理解是正确的,当用户单击对话框上的“ OK
按钮时应该使用close
,而当用户单击“ cancel
按钮时dismiss
吗?
Not necessary. 不必要。 A reason can be self-explaintory, like close a modal due a click on a link inside the modal or an event that does not pass between standard "ok || cancel" 原因可能是不言自明的,例如由于单击模式内部的链接或在标准“确定||取消”之间未通过的事件而关闭模式
Looking at result
would indicate that closing is the way to "properly" close a modal, which resolves the result
promise. 查看result
将表明,关闭是“正确”关闭模式的方式,该模式可以解决result
承诺。
result
(Type: promise
) - Is resolved when a modal is closed and rejected when a modal is dismissed.` result
(Type: promise
)-在关闭模态时解决,在取消模态时拒绝。 Judging by that, I would say that you are correct in your assumption. 以此判断,我认为您的假设是正确的。
Consider the case where you have 'Yes', 'No', and 'Cancel' 考虑您选择“是”,“否”和“取消”的情况
eg. 例如。 Preparing to connect to a chatroom, you might ask the user if they want to use their usual nickname, Yes would result in a connection with their nickname, No would result in a connection with a Guest nickname, and Cancel would result in no connection (dismissed) 准备连接到聊天室时,您可能会问用户是否要使用其惯用的昵称;“是”将导致其昵称与连接;“否”将导致与“访客”昵称具有连接;而“取消”将导致与用户的昵称没有连接(解雇)
Cancel is dismissed, yes and no are closed (with a further result) 取消被取消,是和否被关闭(进一步的结果)
Of course, there could be many more button combinations, but Yes/No/Cancel is quite common. 当然,可以有更多的按钮组合,但是“是/否/取消”很常见。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.