项目中经常会用到确认对话框,而Ext.MessageBox.confirm的返回值是MessageBox本身this
那我们该如何应用confirm呢?
下面看api说明
confirm( String title, String msg, [Function fn], [Object scope] ) : Ext.MessageBox
Displays a confirmation message box with Yes and No buttons (comparable to JavaScript's confirm).
If a callback function is passed it will be called after the user clicks either button,
and the id of the button that was clicked will be passed as the only parameter to the callback
(could also be the top-right close button).
Parameters:
title : String
The title bar text
msg : String
The message box body text
fn : Function
(optional) The callback function invoked after the message box is closed
scope : Object
(optional) The scope (this reference) in which the callback is executed. Defaults to the browser wnidow.
Returns:
Ext.MessageBox
this
看到api我们应该有了方向
第三个参数是一个回调函数,只要我们重写一个方法,传递一个按钮id为参数就像上面说明的一样
If a callback function is passed it will be called after the user clicks either button,
and the id of the button that was clicked will be passed as the only parameter to the callback
这里要说明一下, confirm对话框两个按钮的ID,一个是yes, 一个是no
那么在重写的方法里对传过来的按钮ID进行判断
就能知道用户点击的是哪个按钮?进行的是什么选择
上代码
Ext.MessageBox.confirm("info", "您确定要进行模板删除吗, 原来的模板数据不会再存在?", RetConfirm);
function RetConfirm(btnid)
{
if ( btnid == "yes")
{
if ( g_markSwitch )
{
Ext.Ajax.request({
url: './ext-app/SaveTmpl.asp',
method: 'GET',
success: onSaveSucc,
failure: onSaveFail,
params:{'code': Ext.getCmp('tmpl_id').getValue(), 'name': escape( Ext.getCmp('tmpl_name').getValue()), 'imgsrc': Ext.getCmp('tmpl_imgsrc').getValue()}
});
}
else
{
Ext.Ajax.request({
url: './ext-app/DelTmpl.asp',
method: 'GET',
success: onDelSucc,
failure: onDelFail,
params: {'code': Ext.getCmp('tmpl_id').getValue()}
});
}
}
}
像上面function RetConfirm中对btnid进行判断,然后进行的是不同的业务逻辑