如何在Handlebars中将消息记录到控制台?

Hao*_* Li 5 handlebars.js ember.js

我与Ember.js工作,不知道是否有在车把上的内置功能,可以让我打印到像控制台{{ log "my message" }}类似于我们目前可以与像记录对象做:{{ log this }}?


或者我每次都要定义辅助功能?

但这甚至对我不起作用(点击查看jsbin):

我在HTML Handlebars中:

{{ debug "this is my string" }}
Run Code Online (Sandbox Code Playgroud)

然后在app.js我有:

Ember.Handlebars.helper('debug', function(the_string){
    console.log(the_string);
});
Run Code Online (Sandbox Code Playgroud)

但app.js没有收到the_string,所以the_string在那里未定义,发生了什么?

sel*_*gsz 10

我不确定为什么Ember.Handlebars.helper不起作用......截至目前你可以试试

  Ember.Handlebars.registerHelper('debug', function(the_string){
    Ember.Logger.log(the_string);
    // or simply
    console.log(the_string);
  });
Run Code Online (Sandbox Code Playgroud)


cbn*_*bnz 5

只是为将来发现这个问题的人发布一个新答案。现在有一个更简单的方法。

您的{{debug}}助手有效地内置于本机{{log}}助手中。您还可以使用{{debugger}}帮助程序添加断点。

有关更多信息,请参阅指南。