如何在Chrome / Safari中调试EJS代码 [英] How to Debug EJS code in Chrome/Safari

查看:165
本文介绍了如何在Chrome / Safari中调试EJS代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在CanJS中使用EJS模板,并且正在寻找一种调试EJS代码的方法。目前,firebug可以向我展示EJS中的语法错误,但在其他浏览器中,我什么也看不到,我需要非常仔细地浏览我的EJS文件以解决错误。我在网上搜索,发现了有关 ejs_fulljslint 的信息 https://code.google.com/p/embeddedjavascript / ,但无法正常运行。我将脚本包含在HTML文件中,但仍未收到任何控制台错误。我无法在Web上找到调试示例。

I am using EJS templates with CanJS and are looking for a way to debug my EJS code. Currently firebug can show me the syntax errors in EJS but in other browsers, I am not able to see anything.I need to go through my EJS file very carefully to solve the errors. I searched on web and found out about ejs_fulljslint https://code.google.com/p/embeddedjavascript/ , but not able to run this properly. I included the script into my HTML file but still wasn't getting any console errors. I am not able to find a demo of debugging on web.

有人可以告诉我如何调试EJS代码吗?如果您能提供任何示例,我们将不胜感激。

Can anyone tell me how to debug my EJS code. If you can provide me any example, that will be highly appreciated.

推荐答案

最后,EJS只是转换为JavaScript,因此只需在需要的地方放置 debugger; 语句并打开开发人员工具,就可以解决问题。例如,要在for循环中检查 i 变量,您可以将 debugger; 放置如下:

In the end, EJS just translates to JavaScript and therefore just placing a debugger; statement where you need it and opening developer tools, might do the trick for you. For example, to check on the i variable in a for loop you would place your debugger; like this:

<script type="text/ejs" id="todoList">
  <% for(var i = 0; i < todos.length; ++i) { %>
    <% debugger; %>
    <li><%= this[i].attr('description') </li>
  <% } %>
</script>

这篇关于如何在Chrome / Safari中调试EJS代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆