0

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

1 回答 1

2

只需将声明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');

    // ...
于 2018-01-15T14:54:42.583 回答