在组件内本地公开函数变量
Expose function variables, locally, within component
我有一个 flightJS 组件(不要启动)并且需要一种方法来在我的组件初始化后公开来自 bindTranslations
的翻译文本,以便本地函数可以访问翻译后的值。这是我希望它如何工作的伪代码,但我的 JS 知识让我失望了:(
function paymentForm() {
this.bindTranslations = function() {
var buttonText = I18n.t('js.process_payment_button');
var paragraphText = I18n.t('js.process_payment_paragraph');
return {
button: buttonText,
paragraph: paragraphText
}
};
this.handlePaymentState = function() {
this.select('submitButtons').val(buttonText);
this.select('paymentParagraph').val(paragraphText);
}
this.after('initialize', function() {
this.bindTranslations();
}
}
export default paymentForm;
只需将 buttonText
和 paragraphText
的声明向上移动一级到 parmentForm
。它们将在 bindTranslations
和 handlePaymentState
:
中被捕获
function paymentForm() {
var buttonText;
var paragraphText;
this.bindTranslations = function() {
buttonText = I18n.t('js.process_payment_button');
paragraphText = I18n.t('js.process_payment_paragraph');
// ...
我有一个 flightJS 组件(不要启动)并且需要一种方法来在我的组件初始化后公开来自 bindTranslations
的翻译文本,以便本地函数可以访问翻译后的值。这是我希望它如何工作的伪代码,但我的 JS 知识让我失望了:(
function paymentForm() {
this.bindTranslations = function() {
var buttonText = I18n.t('js.process_payment_button');
var paragraphText = I18n.t('js.process_payment_paragraph');
return {
button: buttonText,
paragraph: paragraphText
}
};
this.handlePaymentState = function() {
this.select('submitButtons').val(buttonText);
this.select('paymentParagraph').val(paragraphText);
}
this.after('initialize', function() {
this.bindTranslations();
}
}
export default paymentForm;
只需将 buttonText
和 paragraphText
的声明向上移动一级到 parmentForm
。它们将在 bindTranslations
和 handlePaymentState
:
function paymentForm() {
var buttonText;
var paragraphText;
this.bindTranslations = function() {
buttonText = I18n.t('js.process_payment_button');
paragraphText = I18n.t('js.process_payment_paragraph');
// ...