在meteorjs中嵌入javascript组件

时间:2015-10-04 16:32:11

标签: javascript meteor meteor-blaze meteor-helper

如何在meteorjs应用程序(使用铁路由器)中将这样的脚本嵌入到模板中?

<!-- TradingView Widget BEGIN -->
<script type="text/javascript" src="https://d33t3vvu2t2yu5.cloudfront.net/tv.js"></script>
<script type="text/javascript">
new TradingView.widget({
  "width": 980,
  "height": 610,
  "symbol": "FX:SPX500",
  "interval": "D",
  "timezone": "exchange",
  "theme": "White",
  // other stuffs...
});
</script>

我获得了小部件代码段here Here是我的示例代码:应用程序不显示任何图表。

1 个答案:

答案 0 :(得分:0)

如果您使用的是Iron Router,则插入头部内容目前不实用。它会产生双头标签的情况。

最简单的方法是创建一个包含脚本内容的JS文件。 Meteor会自动将其包含在应用程序的头部以及其他任何JS中。

实际上,我可能会把它放在模板中

Template.app.onRendered(function() {
new TradingView.widget({
  "width": 980,
  "height": 610,
  "symbol": "FX:SPX500",
  "interval": "D",
  "timezone": "exchange",
  "theme": "White",
  // other stuffs...

});