zoukankan      html  css  js  c++  java
  • Extjs4几个小知识点

    1、Why user "var me=this" in Extjs4?
    有个英文解释很好:

    Say you have a method in your object A which itself makes an ajax request which has a callback. In this callback you want to use a property "blob" of your original object A. You can not use "this.blob" in this callback because "this" does not refer to your object A anymore (Your scope is in the ajax request). For this reason you save "this" to a variable "me" before you call the function and then refer to "me.blob" to reference the porperty A.blob.

    归根结底就是作用域的原因,就是如果你在当前对象中的某一个函数用this的时候this可能不是指代当前的对象了,你要用var me=this;这句话把当前对象的指针保存下来就可以用了。
    举例:

    // a grid, for example
    initComponent: function() {
      var me = this;
      ...
      me.toolbar = new Ext.Toolbar({
        items: [
          { text: 'refresh', handler: function() { me.store.reload(); } }
        ]
      });
    
    inside the handler, me references the grid, while "this" references the button. 
    Surely a source of confusion for many a programmer at some point.
    如果在函数里面写了var me=this;这句话,this指代的是直接调用这个函数的对象,所以在handler函数中用this的话是指代的button而不是grid。因为handler是数据button的。

    2、Ext.Ajax.request()
    Ext.Ajax.request({
        url: 'ajax_demo/sample.json',
        success: function(response, opts) {
            var obj = Ext.decode(response.responseText);
            console.dir(obj);
        },
        failure: function(response, opts) {
            console.log('server-side failure with status code ' + response.status);
        }
    });

    非常重要的方法。

    3、注意store.loadData();store.loadRecords();的使用。

    4、 constructor: function (config) {
            Ext.apply(this, config);
    }
    这是一个构造函数,就是在你利用基类构造对象时把你所有的初始化的参数、属性赋给新建的对象。

  • 相关阅读:
    Spring boot 2.0整合mybatis和druid数据源,基于starter方式
    MySQL 5.7 等高版本关于JDBC驱动的几个问题
    使用maven,包括配置阿里云镜像和eclipse的配置
    vue的学习
    Awesome Vue.js vue.js学习资源链接大全 中文
    vscode
    lombok插件安装
    Spring Boot 面试题
    Get started with Docker for Windows
    详解WebMvcConfigurer接口
  • 原文地址:https://www.cnblogs.com/nannanITeye/p/3216866.html
Copyright © 2011-2022 走看看