Backbone.js 无法访问对象属性
我遇到了一个我真的无法理解的问题......我不确定骨干是否对这些对象做了一些巫术,但我似乎无法获得对它们的原始访问。
我的基本问题是,有时当我加载页面、获取模型并渲染视图时,一个集合只会显示/渲染 50% 的时间。我认为这是模型未填充的问题,但经过一番调查后,我可以看到模型已填充但无法访问。
有人有什么想法吗?我附上了一些工作和不工作的屏幕截图来说明我的观点(理智)。
页面加载良好 - 模型已访问
页面未正确加载 - 模型无法访问
正确加载时的对象 >
未正确加载时的对象
I'm having a problem that I really can't comprehend… I'm not sure if backbone is doing some voodoo to these objects but I can't seem to get even raw access to them.
My basic problem is, sometimes when I load the page, fetch the models and render the views one collection will only show/render 50% of the time. I assumed this was an issue with the model not being populated but after some investigation, I could see the model was populated but not accessable.
Does anyone have any ideas? I have attached a few screenshots of working and not working to illustrate my point(sanity).
Page loading fine - model accessed
Page not loading correctly - model inaccessible
The object when is loading correctly
The object when not loading correctly
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的调试尝试出错了。
console.dir 比那复杂得多。它向你展示的是一个活的物体,而不是真实的物体。
如果您尝试记录
$.extend(true, {}, obj)
(或其他克隆),那么您可以记录真实对象。正如前面提到的,这听起来像是 ajax 的事情。您是否想在加载之前使用它? (但有时你很幸运,那时它已经加载了)。
我们需要更多信息。 jsfiddle 将是最好的。
Your debugging attempts are going wrong.
console.dir is a lot more complex then that. it shows you a live object, not the real object.
If you try to log
$.extend(true, {}, obj)
(or some other clone) then you can log the real object.As mentioned it sounds like an ajax thing. Are you trying to use it before it has loaded? (But sometimes you get lucky and it has loaded by then).
We need more information. A jsfiddle would be the best.