在组件

时间:2018-01-15 14:48:12

标签: javascript twitter-flight

我有一个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;

1 个答案:

答案 0 :(得分:2)

只需将buttonTextparagraphText的声明向上移动一级parmentForm即可。它们将在bindTranslationshandlePaymentState

中被关闭
function paymentForm() {
  var buttonText;
  var paragraphText;
  this.bindTranslations = function() {
    buttonText = I18n.t('js.process_payment_button');
    paragraphText = I18n.t('js.process_payment_paragraph');

    // ...