如何在Ext.Button处理程序中使用up() [英] How to use up() in Ext.Button handler
本文介绍了如何在Ext.Button处理程序中使用up()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
背景:我正在使用sencha Touch 2开发一个MVC应用程序。我正在开发一个包含两个标签的页面。在第一个选项卡中,我在标题栏中有一个按钮。
问题:我无法从按钮处理程序调用任何其他函数。我认为调用函数的作用域有问题。
这是我的代码。
Ext.define('WUPOC.view.WUHomePage', {
extend: 'Ext.TabPanel',
requires:['Ext.TitleBar','Ext.dataview.List','Ext.data.proxy.JsonP'],
alias: 'widget.wuHomePageView',
config: {
fullscreen: true,
defaults: {
styleHtmlContent: true
},
items: [{
title: 'Home',
iconCls: 'home',
items: [{
xtype: 'titlebar',
title: 'Hello',
docked: 'top',
items: [{
xtype: 'button',
text: 'LogOut',
ui: 'action',
itemId: 'newButton',
align: 'right',
handler : function(btn){
console.log('LogOut is tapped'); // This is printed
this.up.onNewButtonTap(); // Throws error
}
}],
}],
}, {
title: 'Contact',
iconCls: 'user',
html: 'Contact Screen'
}]
},
onNewButtonTap: function () {
alert('newNoteCommand');
},
});
我收到如下错误。
Uncaught TypeError: Object function (selector) {
var result = this.parent;
if (selector) {
for (; result; result = result.parent) {
if (Ext.ComponentQuery.is(result, selector)) {
return result;
}
}
}
return result;
} has no method 'onNewButtonTap'
我认为设置按钮的作用域有问题。请帮忙。
谢谢
推荐答案
首先,up
是一个函数,需要这样调用:
this.up();
则this.up()
将只带到按钮的容器,该容器没有方法onNewButtonTap
。您可以一直执行up(),直到得到正确的组件,但这样做会更聪明:
- 将xtype添加到您的视图
- 在up函数中使用此xtype作为选择符:
this.up('myXType').onNewButtonTap();
希望这能有所帮助
这篇关于如何在Ext.Button处理程序中使用up()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文