将组件引用传递给函数

时间:2013-08-15 12:14:45

标签: extjs extjs4

我想知道如何将组件的变量传递给函数?如下所示:

// here is the function that I want to pass 'winArticle' by parameter
var getLevels = function(win) {
    return win.down('fieldset[id=article-fieldset]').items.items.length;
}

var winArticle = new Ext.Window({
   ...

handler : function() {
    // I tried this but nothing happen
    getLevels('winArticle');
}
});

2 个答案:

答案 0 :(得分:1)

您可以为组件添加itemId,您可以使用向下或向上功能来获取组件。

如果你想将组件作为参数传递给函数,它似乎是你想要传递的组件调用函数,所以只需要 this 作为参数传递函数中的组件。确保设置处理程序组件的范围。

修改你的代码就像这样

var winArticle = new Ext.Window({
...
{
  xtype: 'button',
  scope: this,
  handler : function() {
     getLevels(this);
  } 
}
});

答案 1 :(得分:0)

根据你的评论,我不确定哪里有任何混淆,你已经有了对窗口的引用,所以只需通过它。

var myWin = new Ext.window.Window();
someMethod(myWin);
相关问题