Ext.Ajax中scope的作用

在Ext的前台Js中使用Ajax请求,如果想让回调函数中的this作用域跟当前的类一样如何实现呢?Ajax提供了一个参数scope。

详细代码如下;

layout : {
        type : 'accordion',
        titleCollapse : false,
        animate : true,
        activeOnTop : false,
    },
    initComponent : function() {// 通过initComponent来初始化组件
        // 必须要在这里新建一下,不能直接在Store中使用,否则会报错。
        // 也建议在这里初始化一下,根据不同的root节点加载树。
        
        Ext.Ajax.request({// ajax请求的方法
            url : 'menu/queryMenuByCdbh.json',
            params : {
                "node" :'root',
            },
            scope:this,//使回调函数中的this变成当前的类
            success : function(res) {
                var data = Ext.decode(res.responseText);
                if(data.flag=='success'){
                    this.initSysSystem(data.result);
                }else if(data.flag=='ApplicationException'){
                    Ext.Msg.alert('系统提示',data.errorMsg);
                }else{
                    Ext.Msg.alert('系统错误提示',data.errorMsg);
                }
            },
            failure : function(res) {
                var respText = Ext.decode(res.responseText);
                Ext.Msg.alert('错误', respText.error);
            }
        });
        this.callParent(arguments);
    },
    initSysSystem:function(result){

 

这样就可以在success方法中,调用父类中的方法。

posted @ 2015-02-06 15:58  正正杂说  阅读(574)  评论(0编辑  收藏  举报