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);
    }
    这是一个构造函数,就是在你利用基类构造对象时把你所有的初始化的参数、属性赋给新建的对象。

  • 相关阅读:
    如何在Centos官网下载所需版本的Centos
    Zabbix微信告警
    CentOS 7.4 源码编译安装 Redis
    zabbix源码安装后,设置为服务启动和关闭
    MySQL 快速入门教程
    mysql解决 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)的报错
    转:Centos7安装zabbix3.4超详细步骤解析
    centos7使用Gogs搭建Git服务器
    Centos7 使用firewall管理防火墙
    zabbix登录密码重置方法
  • 原文地址:https://www.cnblogs.com/nannanITeye/p/3216866.html
Copyright © 2011-2022 走看看