[extjs]Ext.MessageBox.confirm应用

项目中经常会用到确认对话框,而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进行判断,然后进行的是不同的业务逻辑

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值