【发布时间】:2018-11-07 11:48:33
【问题描述】:
我不知道为什么 jsGrid 在 $(function() (sample) 中有效,但在 jQuery(document).ready (sample 2) 中无效
我在示例 2 中得到的错误是:Uncaught TypeError: Cannot set property '_grid' of undefined
我需要让它像在sample 2 上一样工作 jQuery(document).ready
【问题讨论】:
-
你读过What is the difference between these jQuery ready functions?和相关的吗?请在此处添加您的代码而不是 JSfiddle。如果上述错误没有解决,我建议使用“jsGrid not working with jQuery(document).ready”之类的标题
-
这是一个吊装问题。不能将变量声明放在您尝试访问它们
friends和countries的下面的那个函数中。var将被提升,但在您尝试访问它直到分配完成时将未定义。到那时你已经将undefined传递给插件 -
简单的修复可能是
getFriends()和getCountries()的辅助函数,因此数据可以驻留在下方并将业务逻辑保持在顶部 -
@charlietfl 非常感谢!现在工作jsfiddle.net/8hw0wcjj/2
标签: javascript jquery user-interface frontend jsgrid