iteye_3350 2009-01-06 23:26
浏览 199
已采纳

extjs中addEvents中那个:true参数含义

[code="java"]
Employee = function(name){
this.name = name;
this.addEvents({
"fired" : true,
"quit" : true
});
}
Ext.extend(Employee, Ext.util.Observable);[/code]

查了很多资料 api也查了:

就是不知道

"fired" : true 的 :true 表示什么?

  • 写回答

1条回答 默认 最新

  • bohemia 2009-01-07 09:55
    关注

    [quote] this.addEvents({

    "fired" : true,

    "quit" : true

    }); [/quote]

    addEvents 这个Function是继承自 Observable类;

    可以查看Observable类的addEvents()定义:

    [code="java"] /**
    * Used to define events on this Observable
    * @param {Object} object The object with the events defined
    */
    addEvents : function(o){
    if(!this.events){
    this.events = {};
    }
    if(typeof o == 'string'){
    for(var i = 0, a = arguments, v; v = a[i]; i++){
    if(!this.events[a[i]]){
    this.events[a[i]] = true;
    }
    }
    }else{
    Ext.applyIf(this.events, o);
    }
    },[/code]

    [quote][color=red]Ext.applyIf(this.events, o);[/color][/quote]

    这里可以看到 fired,quit 属性被复制到了this.events队列;
    说明,这两个属性属于event的内容;

    再看到Observable类的addListener()方法
    [code="java"]addListener : function(eventName, fn, scope, o){
    if(typeof eventName == "object"){
    o = eventName;
    for(var e in o){
    if(this.filterOptRe.test(e)){
    continue;
    }
    if(typeof o[e] == "function"){
    // shared options
    this.addListener(e, o[e], o.scope, o);
    }else{
    // individual options
    this.addListener(e, o[e].fn, o[e].scope, o[e]);
    }
    }
    return;
    }
    o = (!o || typeof o == "boolean") ? {} : o;
    eventName = eventName.toLowerCase();
    var ce = this.events[eventName] || true;
    if(typeof ce == "boolean"){
    ce = new Ext.util.Event(this, eventName);
    this.events[eventName] = ce;
    }
    ce.addListener(fn, scope, o);[/code]

    可以看到如下代码被引用
    [quote][color=red]

    o = (!o || typeof o == "boolean") ? {} : o;

    eventName = eventName.toLowerCase();
    var ce = this.events[eventName] || true;
    if(typeof ce == "boolean"){
    ce = new Ext.util.Event(this, eventName);
    this.events[eventName] = ce;
    }
    [/color][/quote]

    就是最终该值,最后被转换成事件对象.被添加了事件处理函数上;

    我的理解:
    [quote]this.addEvents({

    "fired" : true,

    "quit" : true

    }); [/quote]
    设置成false;将不会被处理;
    设置成function;将直接被当作Listener方法处理;

    上面的参照EXT2.2.. 一起学习了.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改