1

我在面板中添加了一个按钮。单击按钮时,将显示一个弹出窗口。我尝试使用 setHandler 更新弹出窗口的内容。但是每当调用 setHandler 时,处理函数就会立即执行。这是示例代码:


    me.panels[i].getDockedItems()[0].setHandler(Popup({html: tiphtml}), this);
    ...
    Popup = function(cfg) {
      cfg = Ext.apply({
        height: 100, 
        width: 200,
        layout: 'fit'
      }, cfg);

      Ext.create('Ext.window.Window', {
          title: cfg.title,
          height: cfg.height,
          width: cfg.width,
          layout: cfg.layout,
          html: cfg.html 
      }).show();
    }
4

1 回答 1

2

您需要将函数嵌套在匿名函数中。您实际上是在代码中调用该函数,而不是传递它。这将起作用:

    me.panels[i].getDockedItems()[0].setHandler(function(){Popup({html: tiphtml})}, this);
    ...
    Popup = function(cfg) {
      cfg = Ext.apply({
        height: 100, 
        width: 200,
        layout: 'fit'
      }, cfg);

      Ext.create('Ext.window.Window', {
          title: cfg.title,
          height: cfg.height,
          width: cfg.width,
          layout: cfg.layout,
          html: cfg.html 
      }).show();
    }
于 2013-02-28T14:14:48.223 回答