zoukankan      html  css  js  c++  java
  • 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方法中,调用父类中的方法。

  • 相关阅读:
    P4630-[APIO2018]Duathlon铁人两项【圆方树】
    P4980-[模板]Pólya定理
    bzoj4589-Hard Nim【FWT】
    CF700E-Cool Slogans【SAM,线段树合并,dp】
    sqrt数据结构
    NOIP历年好题
    ACM题解吖
    [ZJOI2010]排列计数
    [CQOI2014]数三角形
    [SHOI2007]书柜的尺寸
  • 原文地址:https://www.cnblogs.com/sdjnzqr/p/4277375.html
Copyright © 2011-2022 走看看