ExtJS4 MVC:如何按类选择按钮

时间:2012-04-04 13:58:56

标签: javascript model-view-controller extjs

如果有一个网格,我想控制(从控制器)这个网格的tbar中的一些按钮。

我可以找到具有itemId属性的按钮,但如何按类查找按钮,以及需要使用哪个类(有baseCls,cls等,它们不起作用)?

这是我的控制器代码:

Ext.define("Wtb.controller.Schedule",{
extend:'Ext.app.Controller',

    refs:[{
        ref:'grid',
        selector:'button'
    }],
init: function () {

    this.control({
        'button#remove':{
            click:this.Remove
        },
        'button#refresh':{
            click: this.Load
        },
        'button#save':{ //Buttons with id works fine
            click:this.Save
        },
        'button.period':{ //It can't be found, because here is the class
            click:this.changePeriod
        }
    })

这是按钮片段:

{ //Button with ID
    xtype:"button",
    itemId:'refresh',
    text:"Refresh"
},'->',{ //Button with class. I need some buttons, like this.
    xtype:"button",
    text:"Period - day",
    cls:'period',
    value:'day'
}

如何按类从控制器中查找按钮?

1 个答案:

答案 0 :(得分:4)

查看ComponentQuery的文档:http://docs.sencha.com/ext-js/4-0/#!/api/Ext.ComponentQuery

这可以为您提供正确的按钮:

'button[cls=period]'