zoukankan      html  css  js  c++  java
  • ExtJS中如何给Label添加click事件

    代码
          //ExtJS中Ext.form.Label默认是没有click事件的,但由于项目需要,要求给label添加一些其它的事件,本文提供两种方法对这个class进行扩展,方法如下:

    //方法1:

    Ext.onReady(
    function() {
       
    var p = new Ext.ux.MyPanel({
          renderTo : document.body
         });
      });
    Ext.ux.MyPanel 
    = Ext.extend(Ext.Panel, {
       initComponent : 
    function() {
        Ext.apply(
    this, {
           width : 
    200,
           height : 
    200,
           items : [{
            xtype : 
    'label',
            id : 
    'mylabel1',
            html : 
    'Label 1',
            listeners : {
             render : 
    function() {//渲染后添加click事件
              Ext.fly(this.el).on('click',
                
    function(e, t) {
                 
    // do stuff
                 alert('Hi');
                });
             },
             scope : 
    this
            }
           }]
          });
        Ext.ux.MyPanel.superclass.initComponent.call(
    this);
       }
      });

    //方法2:

    Ext.onReady(
    function() {
                
    //在渲染后添加click事件
       Ext.form.Label.prototype.afterRender = Ext.form.Label.prototype.afterRender
         .createSequence(
    function() {
            
    this.relayEvents(this.el, ['click']);
           });
    //这一段一定要放在label之前
       var tempPanel = new Ext.Panel({
          layout : 
    'fit',
           renderTo : document.body,
          items : [{
             xtype : 
    'label',
             text : 
    'label click',
             listeners : {
              
    'click' : {
               fn : 
    function(field) {
                alert(
    "Hi");
               },
               scope : 
    this
              }
             }
            }]
         });
      });
  • 相关阅读:
    0. 序列
    Megacli 常用
    4. Storm可靠性
    3. Storm编程框架
    2. Storm消息流
    1.1 Storm集群安装部署步骤
    poj3723,最 大 生成树
    次短路
    无间道之并查集
    最小生成树二Kruscal算法
  • 原文地址:https://www.cnblogs.com/timy/p/1798020.html
Copyright © 2011-2022 走看看