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方法中,调用父类中的方法。

  • 相关阅读:
    vue 中简单路由的实现
    Vue中对生命周期的理解
    内存泄漏
    前端工程化
    exports 和 module.exports 的区别
    Nodejs的url模块方法
    MongoDB 的获取和安装
    Anjular JS 的一些运用
    移动端vconsole调试
    安装fiddler时,电脑浏览器没网
  • 原文地址:https://www.cnblogs.com/sdjnzqr/p/4277375.html
Copyright © 2011-2022 走看看