如何遍历Ext.menu.Menu框中的项目 - Extjs

时间:2016-06-23 02:14:22

标签: javascript extjs

我使用Ext.menu.Menu列出项目,并想要遍历它们以查找特定值。

new Ext.Container({                
          width: 560,
            height: 250,
            layout: 'hbox',
            items: [
                new Ext.menu.Menu({
                    items: [
                        {
                            text: 'Today',
                            handler: function() {
                            },
                            scope: this
                        }
                    ].concat([
                            {
                                text: 'Yestaerday',
                                handler: function() {
                                },
                                scope: this
                            }, {
                                text: 'Month'
                                handler: function() {
                                },
                                scope: this
                            }
                        ]).concat([
                            {
                                text: 'Year',
                                handler: function() {
                                },
                                scope: this
                         }]
 })

在上面的代码中我尝试删除文本值为" Yestaerday和Month"的项目。如何循环浏览菜单项以查找要删除的等效文本值?thx

2 个答案:

答案 0 :(得分:0)

尝试使用ComponenetQuery

Ext.ComponentQuery.query('button[text=Yestarday],button[text=Month]');

你会得到按钮对象。

答案 1 :(得分:0)

我认为你只需要创建自己的'组件查询'类型函数,它将循环菜单项并找到匹配项。

以这个小提琴为出发点:

https://fiddle.sencha.com/#fiddle/1chu