【问题标题】:Why can't I access variables within an $.each loop in Chrome's debugger?为什么我不能在 Chrome 的调试器中访问 $.each 循环中的变量?
【发布时间】:2016-02-26 23:47:14
【问题描述】:

我想使用调试器在$.each 循环中检查来自test_data(传递到populateChildTable 的对象)的一些属性。当我尝试使用调试器访问它们时出现undefined 错误

var populateChildTable = function(test_data) {

    $.each(test_data.children, function(index, el) {

        $('#my_children tbody')[0].appendChild(createChildRow(el)); // breakpoint here

    })

})

Chrome 版本 48.0.2564.71 测试版(64 位)

【问题讨论】:

  • 当然可以在循环内使用test_data?你试过了吗
  • 是 children() 吗? api.jquery.com/children
  • 编辑帖子以提出不同的问题。傻我,我知道有问题

标签: javascript jquery google-chrome scope


【解决方案1】:

这与this 铬错误有关。

test_data$.each 回调范围内可用,您可以通过使用console.log(test_data) 而不是debugger; 来验证这一点。开发工具优化会导致这种行为,您可以在上面链接的线程中了解这一点。

【讨论】:

    猜你喜欢
    • 2018-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-14
    • 2013-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多