繁体   English   中英

调试Backbone.js

[英]Debugging Backbone.js

我正在寻找调试backbone.js的一些指导。 我正在关注Daily.js骨干教程,并在第9周后遇到了一个错误( http://dailyjs.com/2013/01/24/backbone-tutorial-9/ )。

这是我的错误

[22:47:29.339] "calling request execute"
[22:47:29.423] GET http://localhost:8080/img/glyphicons-halflings.png [HTTP/1.1 304 Not Modified 1ms]
[22:47:29.424] POST https://content.googleapis.com/rpc?key=xxxxxxx [HTTP/1.1 200 OK 168ms]
[22:47:29.546] ReferenceError: id is not defined @ http://localhost:8080/js/lib/underscore.js:1209
[22:47:29.543] "calling options success"

这是带有相应控制台日志记录调用的代码:

Backbone.gapiRequest = function(request, method, model, options) {
    var result;
    console.log("calling request execute")
    request.execute(function(res) {
      if (res.error) {
        if (options.error) options.error(res);
      } else if (options.success) {
        if (res.items) {
          result = res.items;
        } else {
          result = res;
        }
        console.log("calling options success");
        options.success(model, result, request);
      }
      console.log("gapiRequest")
    });
  };

事情正在把我扔掉:

  1. 为什么没有显示最后一个日志(gapiRequest)。
  2. 为什么在两个控制台日志之间发生错误,即使代码中没有任何内容引用id,或者就我所见,任何外部库也是如此。

如果有人知道可能会发生什么事情会很好,那么关于如何调试它的任何信息都会非常好。 可以在当前的Web浏览器中生成堆栈跟踪吗?

TIA,马特

  1. 如果查看时间戳,您的脚本将崩溃:

     [22:47:29.546] ReferenceError: id is not defined @ http://localhost:8080/js/lib/underscore.js:1209 [22:47:29.543] "calling options success" 

    你会看到"calling options success"发生在ReferenceError之前。 这意味着您的客户端收到了结果,但是在渲染模板时您的脚本崩溃了(我猜),可能是因为:

  2. 根据发生异常的库判断(underscore.js),您可能会在下划线模板中的某处引用id 在模板文件中查找类似<%= id%><% id%>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM