本文介绍了如何在Handlebars模板中添加console.log()JavaScript逻辑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个新的Meteor应用程序,我无法弄清楚如何使用Handlebars添加JavaScript逻辑来运行 console.log()在我的每个循环之前。在骨干我会做,<%console.log(data); %> 来测试数据是否被传入。

我不知道如何使用Meteor和Handlebars来做到这一点,我找不到解决方案

I'm in the process of building a new Meteor app and I can't figure out how to add JavaScript logic with Handlebars to run a console.log() before my each loop. In backbone I would just do, <% console.log(data); %> to test that the data was being passed in.
I'm not sure how to do this with Meteor and Handlebars and I couldn't find the solution on their site.

推荐答案

在您的项目中的一个客户端加载的JavaScript文件中创建Handlebars助手:

Create a Handlebars helper in one of the client-loaded JavaScript files in your project:

Template.registerHelper("log", function(something) {
  console.log(something);
});

然后在您的模板中调用它:

And then call it in your template:

{{log someVariable}}

您可以登录当前上下文中只需 {{log this}}

You can log the current context with simply {{log this}}.

)在Meteor应用程序之外的纯手柄,用 Handlebars.registerHelper 替换 Template.registerHelper 。)

(Note that in Meteor before version 0.8, or in pure Handlebars outside of a Meteor app, replace Template.registerHelper with Handlebars.registerHelper.)

这篇关于如何在Handlebars模板中添加console.log()JavaScript逻辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 03:06