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

  • 相关阅读:
    Java设计模式之装饰模式
    学习Emacs系列教程(二):导航
    Android ProgressDialog 延时消失
    java设计模式装饰模式
    Java 字节流和字符流的相互转换
    emacs配置颜色主题
    Android ProgressDialog的使用
    个人管理 时间管理GTD流程图
    jQuery - 列表控件推荐
    WPF - 模板查看工具:Show Me The Template及如何查看第三方主题
  • 原文地址:https://www.cnblogs.com/nannanITeye/p/3216866.html
Copyright © 2011-2022 走看看