【问题标题】:Cant make var available to meteor template无法使 var 可用于流星模板
【发布时间】:2015-05-28 19:57:17
【问题描述】:
<template name="index">
  <textarea id="toSpeech" type="text">Type what you want to say!</textarea>
  <button>
    <span><a href="#" class="btn" id="openBtn">Sounds like</a></span>
  </button>
</template>

<template name="soundsLike">
  <div class="modal fade">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-body">
          <iframe src="{{ reduced }}" style="zoom:0.60" width="99.6%" height="100%" frameborder="0"></iframe>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>
    </div>
  </div>
</template>

Template.index.events({
  // handle the form submission
  'click .btn': function(event) {
    Modal.show('soundsLike')
  }

});

Template.soundsLike.onRendered(function() {
  var src = $("#toSpeech").val();
  var replaced = src.replace(/ /g, '+');
  console.log(replaced);
});

我想通过#openBtn onclick 传递文本区域中的文本。我正在使用 Template.soundsLike.onRenderer,但是该变量在soundsLike 模态模板中不可用

【问题讨论】:

    标签: javascript meteor meteor-blaze


    【解决方案1】:

    如果您使用bootstrap-3-modalusage 部分为您提供了一种将数据上下文传输到您的模式的方法:

    Template.index.events({
      // handle the form submission
      'click .btn': function(event) {
        var src = $("#toSpeech").val();
        var replaced = src.replace(/ /g, '+');
        Modal.show('soundsLike', {replaced: replaced});
      }
    
    });
    
    Template.soundsLike.onRendered(function() {
      console.log(this.data.replaced);
    });
    

    【讨论】:

      猜你喜欢
      • 2019-01-11
      • 2015-02-08
      • 2016-01-07
      • 2016-11-01
      • 2013-05-27
      • 1970-01-01
      • 2018-03-03
      • 2012-11-26
      • 2015-01-10
      相关资源
      最近更新 更多