Я собираюсь задать еще один вопрос о новичке. Я сталкивался с несколькими способами, чтобы ребенок мог ссылаться на функции и данные, определенные на уровне родительского класса, но я не уверен, что это рекомендуемый способ. Ниже приведен пример, с которым я имею дело, но эта тема, как правило, важна для меня, поскольку у меня нет хорошего понимания ссылки и сферы охвата родителей и детей. Как я могу ссылаться на функции и данные родителя из дочернего элемента дочернего элемента?Sencha Touch 2 - Правильный способ для дочернего элемента ссылаться на функцию в родительском?
Как обычно, любая помощь будет высоко оценена.
Мохаммад
Сан-Хосе, Калифорния
/******
This is a floating panel with a formpanel inside it, that has an email field and a button to process the email.
When the button is tapped, I want to call the processEmails() function from the button.
******/
Ext.define('myapp.view.ForwardPanel', {
extend : 'Ext.Panel',
xtype : 'forwardPanel',
initialize: function() {
this.callParent(arguments);
var btn = {
xtype: 'button',
ui: 'action',
text: 'Send',
listeners: {
tap: function(){
processEmails(); //<- **How can I reference and call this function?**
// This function is defined at the parent class level
// (indicated at the bottom of the code listing)
}}
};
var form = {
items: [{
xtype: 'fieldset',
instructions: 'Enter multiple emails separated by commas',
title: 'Forward this message.',
items: [ {
xtype: 'emailfield',
name: 'email',
label: 'Email(s)'
},btn] // The button is added to the form here
}]
};
this.add(form);
},
// this is the parent level function I want to call upon button tap.
processEmails: function(){
console.log('Processing email...');
}
});
Да, я думаю, это удобный способ пройти по родительской ссылке. Благодарю. – Mohammad