这可能是JavaScript范围缺乏理解,但为什么我不能在按下按钮时从面板项目元素中访问this.onLoginTap()。我收到一个错误,指出this.onLoginTap不存在。我现在的解决方案是将项目的声明移动到initComponent方法中,但我仍然想知道为什么我不能访问这个方法。为什么我不能在处理程序中访问Sencha Touch JavaScript配置对象中的方法?
感谢,
菲利普
app.myView = Ext.extend(Ext.Panel, {
fullscreen: true,
scroll: 'vertical',
layout: {
type: 'vbox'
},
items: [{
layout: {
type: 'hbox'
},
items: [ {
xtype: 'button',
text: 'Log In',
ui: 'confirm',
handler: function() {
this.onLoginTap(); // this.onLoginTap is undefined here at runtime.
}
}]
}],
// Controller Dispatchers
onLoginTap: function() {
console.log('onLoginTap');
},
initComponent: function() {
app.myView.superclass.initComponent.apply(this, arguments);
}
});
Ext.reg('myView', app.myView);
感谢您的答复。解决方案1不起作用,所以我仍然难以确定范围问题。我试过了,button.ownerCt不包含该方法。解决方案2和3是合理的,但是,个人而言,我更喜欢在定义了ui组件的地方附加处理程序调用,以便我可以看到发生了什么。但是,我愿意对此进行说服;-)需要进一步思考这个......再次感谢。 –